damiancds Posted March 17, 2010 Share Posted March 17, 2010 I recently found a nice script to create the breadcrumbs for a website. I put it on and changed it a tad (to add styling divs) and after a little toying with, worked great. Right now i'm trying to get rid of displays if the filename is index (right now if i'm on the home page i get Home > (document title)and i tried to get rid of the document title part, only if it was an index.php fileCode that works (without trying to remove the index file's title: function breadcrumbs(){ sURL = new String; bits = new Object; var x = 0; var stop = 0; var output = "<div class='crumb'> <a class='crumb' href=\"/\">Home</a> > "; 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 class='crumb' href=\""; for(y=1;y<x-i;y++){ output += "../"; } output += bits[i] + "/\">" + bits[i] + "</a> > "; } document.write(output + document.title + "</div>");} Code that didn't work function breadcrumbs(){ sURL = new String; bits = new Object; var x = 0; var stop = 0; var output = "<div class='crumb'> <a class='crumb' href=\"/\">Home</a> > "; sURL = location.href; sURL = sURL.slice(8,sURL.length); chunkStart = sURL.indexOf("/"); sURL = sURL.slice(chunkStart+1,sURL.length) var filename = url.substring(url.lastindexOf("\\")+1,url.lastindexOf("\."); 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 class='crumb' href=\""; for(y=1;y<x-i;y++){ output += "../"; } output += bits[i] + "/\">" + bits[i] + "</a> > "; }if(filename == "index"){ document.write(output + "</div>");}else{ document.write(output + document.title + "</div>");}} oh, and i found the url.substring(url.lastindexOf("\\")+1,url.lastindexOf("\."); from somewhere where they were trying to get the file name of the documentIs there something i'm doing wrong here?thanks, Link to comment Share on other sites More sharing options...
justsomeguy Posted March 17, 2010 Share Posted March 17, 2010 The path isn't separated with \ characters, it's separated with /. Link to comment Share on other sites More sharing options...
damiancds Posted March 17, 2010 Author Share Posted March 17, 2010 Ok, thanksafter some fiddling I got it where I wanted, but it turns out it won't work for what I wanted, (the way I set up my links, I link to the folder, so detecting the url doesn't give the actual index.php for that folder)but thanks, if I ever need this for anything else, i'll have something working to base it off of Link to comment Share on other sites More sharing options...
damiancds Posted March 24, 2010 Author Share Posted March 24, 2010 Okay, I decided to go back and just put a check in for all of my possible folders and now nothing comes up like thatas in Folder > (index.php's title)all of them just come up Folder >pretty much just a status report really Link to comment Share on other sites More sharing options...
justsomeguy Posted March 24, 2010 Share Posted March 24, 2010 The code above gets the title of the current document, not necessarily index.php. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.