Solved

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

Posted on 2007-11-14
3
2,351 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML5 Looping table certain Cell 11 55
binding event to form in window.open 9 39
jquery tab header text 1 23
Copying table data to one another 15 31
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

830 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