Solved

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

Posted on 2007-11-14
3
2,350 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
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 350 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

821 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