/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Javascript breadcrumbs.

I have a javascript that writes breadcrumbs based on the browser location pathname as follows:

[CODE] function breadcrumbs(sClass, sDelimiter)
{
if(!sDelimiter) sDelimiter = ‘>>’;
var sURL = (location.pathname.indexOf(‘?’) != -1) ? location.pathname.substring(0, location.pathname.indexOf(‘?’)) : location.pathname;
sURL = (location.pathname.charAt(0) == ‘/’) ? location.pathname.substring(1) : location.pathname;
var aURL = sURL.split(‘/’);
if(aURL)
{
var sOutput = ‘<a href=”/”>Home</a> ‘ + sDelimiter + ‘ ‘;
var sPath = ‘/’;
for(var i = 0; i < aURL.length; i++)
{
sPath += aURL[i] + ‘/’;
sOutput += ‘<a href=”‘ + sPath + ‘”‘;
if(sClass) sOutput += ‘ class=”‘ + sClass +'”‘;
sOutput += ‘>’ + aURL[i] + ‘</a>’;
sOutput += ‘ ‘ + sDelimiter + ‘ ‘;
}
sOutput += document.title;
document.write(sOutput);
}
}[/CODE]

It works great but I would like to be able to specify an individual URL for “home”, which also happens to be a subdirectory. So for instance, my website is: [url]http://biology.college.edu[/url] (which is actually located at [url]http://www.college.edu/biology/[/url] … I’d like for “home” in the javascript above to reflect Biology Home (based on the biology.college.edu link) and then each page to come off that.

Secondly, I’ve noticed that if I’m using the breadcrumbs on an index.html file of a directory (lets say ‘faculty’), then it shows up as “Home >> faculty >> >> page title” …. I’d prefer the output to be “Home >> faculty” if possible. Where would I make these 2 changes? I tried but I farked it all up.

Thanks!!!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@LeeUAug 23.2006 — See if [URL=http://javascript.internet.com/navigation/breadcrumb-trails.html]this one[/URL] will do the trick.
Copy linkTweet thisAlerts:
@lilqhgalauthorAug 23.2006 — Very cool Lee! Thanks!!!
Copy linkTweet thisAlerts:
@LeeUAug 23.2006 — Glad I could help.
×

Success!

Help @lilqhgal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...