Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2004, 05:23 PM   PM User | #1
JustJon
New to the CF scene

 
Join Date: Oct 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
JustJon is an unknown quantity at this point
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);
}
JustJon is offline   Reply With Quote
Old 11-08-2004, 06:59 PM   PM User | #2
Garadon
Regular Coder

 
Join Date: Jul 2002
Posts: 698
Thanks: 0
Thanked 0 Times in 0 Posts
Garadon is an unknown quantity at this point
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.
Garadon is offline   Reply With Quote
Old 11-08-2004, 11:30 PM   PM User | #3
JustJon
New to the CF scene

 
Join Date: Oct 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
JustJon is an unknown quantity at this point
Thanks I will investigate further.
JustJon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:23 AM.


Advertisement
Log in to turn off these ads.