Altering Javascript for breadcrumb nav
I am using the Javascript below (sourced from evolt.org) to create a breadcrumb navigation system for a project I'm working on. It works fine, except that it calls up the current document name from the HTML title of the document and I would like to exclude a piece of text from the titles. Is this possible?
I'm intending all HTML titles on the site to be structured as: 'page name - organisation name', but the organisation name looks a bit silly in the breadcrumb nav. Is there some simple line of code to add which would remove this?
Thankee! And a pleasant Easter-type thing to all.
home > ";
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 += "" + bits[i] + " > ";
}
document.write(output + document.title);
}
// end hiding script from old browsers -->
ROB posted this at 17:31 — 3rd April 2002.
They have: 447 posts
Joined: Oct 1999
//substitute this line
document.write(output + document.title);
//with these lines where '- organisation name' the text you want to get rid of
var strTitle = document.title.replace(/- organisation name/,"");
document.write(output + strTitle);
cheers
detox posted this at 13:52 — 4th April 2002.
They have: 571 posts
Joined: Feb 2001
how did that work?
Thanks Howard Stern......
Sparklebug posted this at 14:19 — 4th April 2002.
They have: 54 posts
Joined: Oct 2001
Hi Detox and Howard Stern.
It worked perfectly - thank you very much.
However, I've now discovered with more experimenting (which is ongoing as I write!) that this script does not remove the underscores in directory names. So if I have a directory called "member_login" it appears with the underscore in the breadcrumbs. Is there an easy way to remove this or to enable me to have the script re-name directories?
I have sourced another script which allows me to re-name directories and is apparently more compatible with older browers, however, it seems to include the actual filename of the document (eg. 'template.htm') in the breadcrumb with a hyperlink to itself, followed by the HTML title of the same document with no hyperlink (as it should be). So in the following example 'foo.htm' and 'members' corner' are in fact the same document:
home > This is a test > foo.htm > members' corner
I'll paste this script below to see if anyone has any tips for fixing it. (Oh - and how do I remove the organisation name from the title in this script as well, just in case it turns out to be usable!).
Thanks for your help - it is very much appreciated!
Bug
var dList = new Array();
var nList = new Array();
// dir member_login to This is a test
dList[0] = 'member_login';
nList[0] = 'This is a test';
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 = 'Home ' + sDelimiter + ' ';
var sPath = '/';
for(var i = 0; i < aURL.length; i++)
{
if(aURL[i].indexOf('.html')!=-1)continue;
sPath += aURL[i] + '/';
for(var s = 0; s < dList.length; s++)if(aURL[i]==dList[s])aURL[i]=nList[s];
sOutput += '' + aURL[i] + '';
sOutput += ' ' + sDelimiter + ' ';
}
sOutput += document.title;
document.write(sOutput);
}
}
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.