Breadcrumbs (folder based)

Information on ASP, ASP.NET, PHP, HTML, Javascript and anything else WWW related.

Breadcrumbs (folder based)

Postby admin on Wed Oct 29, 2008 10:11 pm

Qualifications:
1. You MUST use underscores to seperate file names like file_name.asp. this program will remove the underscores in the breadcrumbs.
2. You will want to put the files and folders in a structured envirnoment.
default.asp
folder1 - default.asp
folder1 - file_name1.asp
folder1 - file_name2.asp
folder2 - default.asp
folder2 - file_name2.asp
folder2 - contact_us.asp


Then create a crumbs.js file and here is the code that goes inside of it:
Code: Select all
function breadcrumbs()
{   
   sURL = new String;
   bits = new Object;
   var x = 0;
   var stop = 0;
   var output = "<a href=\"/\">Home</a> &nbsp;>&nbsp; ";
   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 += "<a href=\"";
   for(y=1;y<x-i;y++){
     output += "../";
   }
   output += bits[i] + "/\">" + bits[i].replace(/_/g, ' ').toLowerCase() + "</a> &nbsp;>&nbsp; ";
   }
       
   var sPage = location.href.substring(location.href.lastIndexOf('/') + 1);
   if(sPage.length > 0)
   {
      if(sPage.indexOf('.') > 0)
      {
         sPage = sPage.substring(0, sPage.indexOf('.')).toLowerCase();
         
         if(sPage != 'default' && sPage != 'index')
            output += sPage.replace(/_/g, ' ');
      }
   }
   
   document.write(output);
}

reference the crumbs.js from the page like this:
Code: Select all
<script language="JavaScript" src="crumb.js"></script>


and add an element inside the page like this:
Code: Select all
<td class="info"> <script language="JavaScript">breadcrumbs();</script></td>
admin
Site Admin
 
Posts: 6
Joined: Wed Oct 29, 2008 12:44 pm

Return to Web Site Assistance

Who is online

Users browsing this forum: No registered users and 1 guest

cron