View Full Version : Help with breadcrumbs please

11-08-2004, 06:23 PM

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:


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)

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

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

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

11-08-2004, 07:59 PM
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.

1:one 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.

11-09-2004, 12:30 AM
Thanks I will investigate further.