From the January 2016 Issue of Prestwood eMag
JavaScript Coding Tasks:
You Are Here Location Script
Posted
16 years ago on 12/3/2008
Take Away: A Javascript "You are here:" location script that uses your folder path to indicate location.
KB101663
We used this script on prestwood.com for several years but stopped using it in December 2008 in favor of a simpler look.
The Script Here's the script:
<!-- // location.js by Mike Prestwood. // // Global variables. // var sPath = location.href; var pages = sPath.split("/"); var sTemp; // // Remove extension. // function GetPageName(PageName) { var sName = PageName; var sTemp; // String .html if (PageName.substr(PageName.length-5, 5) == '.html') sName = PageName.substr(0, PageName.length-5); // String .htm if (PageName.substr(PageName.length-4, 4) == '.htm') sName = PageName.substr(0, PageName.length-4); // String .shtml if (PageName.substr(PageName.length-6, 6) == '.shtml') sName = PageName.substr(0, PageName.length-6); // String .asp if (PageName.substr(PageName.length-4, 4) == '.asp') sName = PageName.substr(0, PageName.length-4); // String .aspx if (PageName.substr(PageName.length-5, 5) == '.aspx') sName = PageName.substr(0, PageName.length-5); // String .pl if (PageName.substr(PageName.length-3, 3) == '.pl') sName = PageName.substr(0, PageName.length-3); // String .cgi if (PageName.substr(PageName.length-4, 4) == '.cgi') sName = PageName.substr(0, PageName.length-4); // Uppercase first character. sTemp = sName.substr(0, 1); sTemp = sTemp.toUpperCase(); sName = sTemp + sName.substr(1,sName.length); if (sName == 'Estore') sName = 'eStore'; return sName;} // // Write You are here: plus pages based on href. // document.write('You are here: <a href="/">Home</a>'); for (var Counter1=3; Counter1 < pages.length;) { sTemp = GetPageName(pages[Counter1]); if (sTemp == 'ASPSuite' && Counter1 <= 3) sTemp = 'PPC'; if (pages[Counter1+1] == '' || pages[Counter1+1] == 'default.asp' || pages[Counter1+1] == 'home.asp') { document.write(' > ' + sTemp); } else { if (Counter1 == pages.length-1){ // Write last section. if (sTemp != '' && sTemp != 'Index' && sTemp != 'Home' && sTemp != 'Default') document.write(' > ' + sTemp); } else { document.write(' > <a href="'); for (var Counter2=3; Counter2 <= Counter1;){ document.write('/' + pages[Counter2]); Counter2++; } document.write('">' + sTemp + '</a>'); } } Counter1++ } //--> Save this script as location.js and put it in the root of your website.
Usage Here's the include HTML:
<script language="JavaScript" src="/location.js"></script> In the beginning, we had this at the top of every page. The top started to look cluttered so we moved it to the bottom of the page. In December 2008 we stopped using it entirely primarily because prestwood.com is so complicated already and the "feel" of the website is better without it.
1 Comments.
Share a thought or comment...
This will be a progressive innovation! I can hardly wait to see the dispatch of AutoCAD programming and also they can check essaywritinglab services to manage their task. The designing understudies will be pleased with their vocation determination. Much obliged for sharing.
KB Post Contributed By Mike Prestwood:
Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions . Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books . If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.
KB Article #101663 Counter
11352
Since 12/3/2008