Urgent Javascript help needed - Breadcrumb Script

Discussion in 'JavaScript' started by txwebdesign, Nov 26, 2006.

  1. #1
    First, I used this script:
    http://www.javascriptkit.com/script/script2/breadcrumb.shtml

    The script works fine but all of my pages are showing up in just one
    "directory" (Home.) For instance, Home > How to Order, Home > Custom Drapes, etc... The script supposedly shows the links based on the "Directory Tree" but I'm not sure how to edit my web pages in the Directory Tree. I tried just creating the navigation by dragging & dropping the pages into the navigation tree but that didn't work.

    Does anyone know how to create the directories or make certain pages "under" other pages?

    Thanks!
    Beverly
     
    txwebdesign, Nov 26, 2006 IP
  2. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It appears you create your structure by placing your pages within folders. The script uses those folder names to populate your breadcrumbs.

    So, "Home > How to Order" would be achieved by having a How To Order page in your root web directory. If you wanted "Home > How to Order > Order By Credit Card" you would need to have Order By Credit Card inside a How To Order folder.
     
    the_pm, Dec 4, 2006 IP
  3. txwebdesign

    txwebdesign Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Need further help, please...

    When I create a folder (ie "Sample Folder"), when it shows up in my browser, it shows as "Sample%20Folder" - How do I get rid of the "%20" that shows up where I have a space in the folder name? Thanks!!
     
    txwebdesign, Dec 7, 2006 IP
  4. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try adding:

    url = url.replace(/%20/g,' ');
    Code (markup):
    right before the writeln statement. That should replace all instances of %20 with a space.
     
    the_pm, Dec 7, 2006 IP
  5. txwebdesign

    txwebdesign Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Can you confirm where "right before the writeln statement" is? Do you mean before this line?

    document.write(output + document.title);

    Thanks!
     
    txwebdesign, Dec 7, 2006 IP
  6. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Umm, I'm not seeing the line of code you referenced.

    Here - I pulled the script off the link you provided in your first post, and I inserted a little comment to tell you where to put that one line of code I wrote:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    
    //Bread crumb script - Kevin Lynn Brown
    //Duplicate directory names bug fix by JavaScriptKit.com
    //Visit JavaScript Kit (http://javascriptkit.com) for script
    
    var path = "";
    var href = document.location.href;
    var s = href.split("/");
    for (var i=2;i<(s.length-1);i++) {
    path+="<A HREF=\""+href.substring(0,href.indexOf("/"+s[i])+s[i].length+1)+"/\">"+s[i]+"</A> / ";
    }
    i=s.length-1;
    path+="<A HREF=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"\">"+s[i]+"</A>";
    var url = window.location.protocol + "//" + path;
    
    // \/ \/ \/ \/ \/ PUT YOUR CODE IN HERE \/ \/ \/ \/ \/ 
    
    // /\ /\ /\ /\ /\ PUT YOUR CODE IN HERE /\ /\ /\ /\ /\
    
    document.writeln(url);
    //-->
    </script>
    
    <p align="left"><font face="arial" size="-2">This free script provided by <a target=_top href="http://javascriptkit.com">JavaScript Kit</a></font></p>
    Code (markup):
    Can't miss it :)

    If this isn't the script you're using, post the actual script, and I'll edit that one for you.
     
    the_pm, Dec 7, 2006 IP
  7. txwebdesign

    txwebdesign Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    txwebdesign, Dec 7, 2006 IP
  8. txwebdesign

    txwebdesign Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Script looks like this:

    function breadcrumbs(){
    sURL = new String;
    bits = new Object;
    var x = 0;
    var stop = 0;
    var output = "<a href=\"/\">Home</a> &nbsp;&#187;&nbsp; ";
    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){
    output += "<a href=\"";
    for(y=1;y<x-i;y++){
    output += "../";
    }
    output += bits + "/\">" + bits + " &nbsp;&#187;&nbsp; ";
    }
    document.write(output + document.title);
    url = url.replace(/%20/g,' ');}

    // -->
    </script>
     
    txwebdesign, Dec 7, 2006 IP
  9. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well yes, it won't work because the script variable is different here than in the first script you linked :)

    Try this:

    Function breadcrumbs(){
    sURL = new String;
    bits = new Object;
    var x = 0;
    var stop = 0;
    var output = "<a href=\"/\">Home</a> &nbsp;»&nbsp; ";
    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){
    output += "<a href=\"";
    for(y=1;y<x-i;y++){
    output += "../";
    }
    output += bits + "/\">" + bits + " &nbsp;»&nbsp; ";
    ourput = output.replace(/%20/g,' ');
    }
    document.write(output + document.title);
    }
     
    the_pm, Dec 7, 2006 IP
  10. txwebdesign

    txwebdesign Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    txwebdesign, Dec 7, 2006 IP
  11. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Try reverting it back to the original. I'm using the markup you provided above to test this, and it's not working. If I can pull the working markup out of your site, I'll be able to modify it properly. Thanks!
     
    the_pm, Dec 8, 2006 IP
  12. txwebdesign

    txwebdesign Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    txwebdesign, Dec 11, 2006 IP