Automatic Breadcrumbs
It is possible to hard-code the links in a breadcrumb trail - i.e. to add all the links manually. It is also possible to automatically produce a breadcrumb trail for all pages. This can be done server-side using XSSI, ASP, ColdFusion or PHP. It can also be done client-side using JavaScript.
This is working at the top of every page in the Materials site.
You need to add the function JavaScript to the HEAD of every page and the call to the function in the BODY of every page, wherever you would like the breadcrumb trail to appear. You can add the call to the function multiple times in the same page.
1 2 <HEAD> 3 <script language="JavaScript"> 4 <!-- 5 function breadcrumbs(){ 6 sURL = new String; 7 bits = new Object; 8 var x = 0; 9 var stop = 0; 10 var output = "<div class=topnav><A HREF=/>Hyperdisc</A> » "; 11 12 sURL = location.href; 13 sURL = sURL.slice(8,sURL.length); 14 chunkStart = sURL.indexOf("/"); 15 sURL = sURL.slice(chunkStart+1,sURL.length) 16 17 while(!stop){ 18 chunkStart = sURL.indexOf("/"); 19 if (chunkStart != -1){ 20 bits[x] = sURL.slice(0,chunkStart) 21 sURL = sURL.slice(chunkStart+1,sURL.length); 22 }else{ 23 stop = 1; 24 } 25 x++; 26 } 27 28 for(var i in bits){ 29 output += "<A HREF=\""; 30 for(y=1;y<x-i;y++){ 31 output += "../"; 32 } 33 output += bits[i] + "/\">" + bits[i] + "</A> » "; 34 } 35 document.write(output + document.title); 36 document.write("</div>"); 37 } 38 // --> 39 </script> 40 </HEAD> 41 42 43 <BODY> 44 45 <SCRIPT LANGUAGE="JavaScript" TYPE='text/javascript'>breadcrumbs()</SCRIPT> 46 47 </BODY>
Points to note about this version of the script:
* It wraps the entire breadcrumb trail in a CSS class called "topnav". You can style this however you like, or you could modify the script to change 'topnav' to any CSS class name you want.
* It names the site "Hyperdisc". You need to modify the script to change the name to something else.
* It assumes that the homepage of the site is in the root directory of the web server. If the homepage of your site is actually in a sub-directory, you would need to seriously modify the script.
* You need to have an index.htm (or equivalent) file in each directory or the user will experience 403 errors.
* Apparantly this script causes errors in older browsers.
* Also note that this script does not work in frames.