BreadcrumbJS by Daniel Abrams | JavaScriptSource

BreadcrumbJS by Daniel Abrams

Daniel Abrams Mar 16, 2012

Abstract

BreadcrumbJS parses URL of current page into hyperlinked segments (breadcrumbs).

Description

BreadcrumbJS parses URL of current page into hyperlinked segments (breadcrumbs), for use as site navigation tool. Compatible with Firefox, Internet Explorer (IE), Chrome, Safari, and Opera.

Code Snippet

<script type="text/javascript"> <!-- Begin // Version 1.10 // Copyright 2005-2012, Virtual Solutions. Restricted use is hereby granted (both personal and commercial use allowed so long as this code is  // not sold, or distributed in altered form), providing this header is fully maintained. [http://www.monster-submit.com] var base	= "http://www.yourdomain.com"; var altbase	= "http://yourdomain.com"; var url		= location.href; var parts	= url.split(base); if (! parts[1]) { 	base	= altbase; 	parts	= url.split(altbase); } var segs	= parts[1]; var segs	= segs.split("/"); var ahref	= base; var str		= '<a class="special" href="' + base + '">Home</a> > '; for (var loop = 1; loop < segs.length; loop++) { 	var st	= doCase(segs[loop]); 	ahref	= ahref + "/" + segs[loop]; 	str 	= str + '<a class="special" href="' + ahref + '">'; 	st		= st.replace(/\.(.*)$/, ""); 	st		= st.replace(/_/g, " "); 	str		= str + st; 	if (loop == (segs.length - 1)) { str = str + '</a>'; } 	else { str = str + '</a> > '; } } document.write(str); function doCase(str) { 	return(str.charAt(0).toUpperCase() + str.substr(1)); } // End --> </script>

Leave a Response

(0 comments)