Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change "%20" in JavaScript to a html-friendly "space" character in a breadcrumbs script

Posted on 2007-11-14
3
Medium Priority
?
2,358 Views
Last Modified: 2010-04-21
I am using a script to create breadcrumbs on my website.  The code is posted below.  If one of the folders on the website has spaces, it displays the breadcrumb with the %20 instead an "html" space character, usually "nbsp;"

Can someone show me how to edit my script to do this?  By the way, I don't have great javascript skills.  This is a slightly modified script I found on the web.  Thanks.  

CODE:

function breadcrumbs(){
  sURL = new String;
  bits = new Object;
  var x = 0;
  var stop = 0;
  var output = "<a href=\"/\" class=\"headlinkText\">Home</a>  >  ";
  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 class=\"headlinkText\" href=\"";
    for(y=1;y<x-i;y++){
      output += "../";
    }
    output += bits[i] + "/\">" + bits[i] + "</a>  >  ";
  }
  document.write(output + "<span class=\"style2\">" + document.title + "</span>");
}
0
Comment
Question by:jibip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 1400 total points
ID: 20284442
jibip,

The easiest solution would be to try ...

    output += bits[i] + "/\">" + unescape(bits[i]) + "</a>  >  ";

I believe that is the line that actually prints it.  Let me know if that is wrong or doesn't work.  We can use a replace instead but the unescape is the simplest and should do it (replaces %20 with a space).

Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Closing Comment

by:jibip
ID: 31409236
easy answer, as I suspected.  Thanks!
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20290543
I'm glad that worked for you.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question