Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now