WA
07-18-2002, 12:46 PM
This is one of the more impressive JavaScripts that have come my way, so I thought I'd post it. I have to mention that it was submitted by a visitor which in turn did not write it (original author according to credits is Kevin Lynn Brown).
Basically, this script displays on any page a "trail" (aka bread crumb) of where the viewer is currently at in relationship to the rest of the site. It does so by examining the directories that prefix the page, and displaying this containership (using links).
A bug was found and fixed by myself. The bug basically caused the script to mess up if there are any duplicate directory names in the URL.
To use this script, just add it to your page:
<SCRIPT LANGUAGE="JavaScript">
<!--
//Author: Kevin Lynn Brown
//Bug fix: By George of JavaScriptKit.com
var path = "";
var href = document.location.href;
var s = href.split("/");
for (var i=2;i<(s.length-1);i++) {
path+="<A HREF=\""+href.substring(0,href.indexOf("/"+s[i])+s[i].length+1)+"/\">"+s[i]+"</A> / ";
}
i=s.length-1;
path+="<A HREF=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"\">"+s[i]+"</A>";
var url = window.location.protocol + "//" + path;
document.writeln(url);
//-->
</script>
You can view a demo of this here: http://javascriptkit.com/script/script2/breadcrumb.shtml
I'm sure people will be coming up with regular expression versions of the above, perhaps with more features.
Basically, this script displays on any page a "trail" (aka bread crumb) of where the viewer is currently at in relationship to the rest of the site. It does so by examining the directories that prefix the page, and displaying this containership (using links).
A bug was found and fixed by myself. The bug basically caused the script to mess up if there are any duplicate directory names in the URL.
To use this script, just add it to your page:
<SCRIPT LANGUAGE="JavaScript">
<!--
//Author: Kevin Lynn Brown
//Bug fix: By George of JavaScriptKit.com
var path = "";
var href = document.location.href;
var s = href.split("/");
for (var i=2;i<(s.length-1);i++) {
path+="<A HREF=\""+href.substring(0,href.indexOf("/"+s[i])+s[i].length+1)+"/\">"+s[i]+"</A> / ";
}
i=s.length-1;
path+="<A HREF=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"\">"+s[i]+"</A>";
var url = window.location.protocol + "//" + path;
document.writeln(url);
//-->
</script>
You can view a demo of this here: http://javascriptkit.com/script/script2/breadcrumb.shtml
I'm sure people will be coming up with regular expression versions of the above, perhaps with more features.