I have some Javascript I am using on my site that automatically generates breadcrumbs based on my file structor. The problem I am having is that the names it displays are based on the file names, and some times those names have under scores in them. here is an example:
Home / Marketing / News_events / News & Events Home Page
What I would like to do is remove the under score in News_events and replace it with a space... same with all the bread crumbs on the site.
My Java Script is not very good but I think I have to add something like this:
string.replace(/_/g,' ');
I'm just not sure where or how to place it with in the Javascript.
Here is the full Javascript:
function breadcrumbs(){
sURL = new String;
bits = new Object;
var x = 0;
var stop = 0;
var output = '<a href="/"><i class="fa fa-home fa-lg"></i></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 href=\"";
for(y=1;y<x-i;y++){
output += "../";
}
output += bits[i] + "/\">" + bits[i] + "</a> / ";
}
document.write(output + document.title);
}
Any help would be greatly appreciated!
replacereturns:string = string.replace(/_/g,' ');.replace('_', ' ')would be far more efficient.