Your full service technology partner! 
-Collapse +Expand
Search JavaScript Group:

-Collapse +Expand JavaScript Store

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...JavaScript a...Coding Tasks   Print This     
  From the January 2016 Issue of Prestwood eMag
JavaScript Coding Tasks:
You Are Here Location Script
Posted 12 years ago on 12/3/2008
Take Away: A Javascript "You are here:" location script that uses your folder path to indicate location.


We used this script on 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]);
       document.write('">' + sTemp + '</a>');

Save this script as location.js and put it in the root of your website.


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 is so complicated already and the "feel" of the website is better without it.


Share a thought or comment...
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1293A1
Enter key:
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 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.

Visit Profile

 KB Article #101663 Counter
Since 12/3/2008
Sales Website: Or visit our legacy sales site:

©1995-2020 Prestwood IT Solutions.   [Security & Privacy]