Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with breadcrumbs please

    Hi,

    I'm trying implement a javaScript breadcrumbs trail on a site I am working on. I have used the code kindly provided on the evolt site:

    http://www.evolt.org/article/Breadcr...ript/17/15480/

    as my starting point, but have needed to make some changes to accommodate my needs. I only want the breadcrumbs to plot a certain depth into the site and have managed to do this, but only by hardcoding the directories I want it to plot into an array and then checking against this array. (There must be a better way?)

    My other issue is that I want it only to display a link back to the index within a directory if the current page is not the index itself. (ie no pages with links to themselves, just the page titles).

    I have tried to do this using the same method of checking against an array but it's getting quite complicated with a lot of loops going on.

    As you may be able to tell from the code I'm new to all this so any help with either issue would be much appreciated. Thanks in advance



    function breadcrumbs(){
    sURL = new String;
    bits = new Object;
    var x = 0;
    var stop = 0;
    var output = "<A HREF=\"/\">HOME</A> > ";
    include = new Array ("directory1","directory2","directory3","etc");

    sURL = location.href;
    sURL = sURL.slice(8,sURL.length);
    chunkStart = sURL.indexOf("/");
    sURL = sURL.slice(chunkStart+1,sURL.length)

    while(!stop){
    chunkStart = sURL.indexOf("/");
    if (chunkStart != -1){
    bits[x] = sURL.slice(0,chunkStart)
    sURL = sURL.slice(chunkStart+1,sURL.length);
    }else{
    stop = 1;
    }
    x++;
    }

    for(var i in bits){
    for (j=0; j<include.length; j++){
    if(bits[i] == include[j]){
    output += "<A HREF=\"";
    for(y=1;y<x-i;y++){
    output += "../";
    }
    newBits1 = bits[i].replace('_',' ');
    newBits2 = newBits1.toUpperCase();
    output += bits[i] + "/\">" + newBits2 + "</A> > ";
    }
    }
    }

    title = document.title.toUpperCase();
    document.write(output + title);
    }

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    there is at least 3 ways

    1:the one ur using.
    2:hardcoding the depth you want in into the script.
    3:sending a depth value in the call to the function.

    comments:
    1ne as you have tried means array and lots of them
    2:means all your sites will only go to a certain depth.
    3:means that you will have to write a number in the function call but if you know where u put ur stuff and how deep u wanna go that shouldn't be hard.

  • #3
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks I will investigate further.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •