Forum Moderators: open
I have the following code which does my "breadcrumbs" for me.
function breadcrumbs(){
sURL = new String;
bits = new Object;
var x = 0;
var stop = 0;
var output = "<A HREF=\"/\">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 HREF=\"";
for(y=1;y<x-i;y++){
output += "../";
}
output += bits[i] + "/\">" + bits[i] + "</A> > ";
}
document.write(output + document.title);
}
I have different folders for my webpages - ie "new products", "back order" etc etc
The breadcrumbs work fine and does what it should, but when it displays my folders it shows it as new%20procucts/back%20order/index.html.
This obviously does not look good and actually of no help to my clients when displayed like this.
Is there somehow in which I can change this to show "new products/back order/index.html" withou the %20.
Regards,
LL
Thanks for the reply. I also thought of this, but dont really like it as the underscore or hyphen will still be very clear on my breadcrumbs. To be honest, I have never seen breadcrumbs on other sites that look like that, so there must be a way around it......... Unless they have more sophisticated "breadcrumb code" than I do, which is probably the case as mine is very basic - as you can see.
I dont mind the %20 in my actual URL, but I do not want %20 or underscore or hyphen to show in my breadcrumbs!
LL
That's why you won't see the %20 as they will grab the category, product name from the db field, which CAN contain spaces, use that for the text and then replace the text with something else when creating the actual link.
I would imagine there is a way to do something similar with javascript, by having one variable for the URL and one for the link text and substituting an actual space for the %20 in the link text variable (but I could be wrong...I suck at javascript).
the underscore or hyphen will still be very clear on my breadcrumbs.
You *really* shouldn't be using spaces in any of your file names and URL's. Although modern servers are able to resolve the URL's, as mentioned any search engine out there will have to encode the spaces so even if you get it to display as file name.htm in your breadcrumbs, on a search engine it will display as file%20name.htm, which you will have no control over.
It is not the best solution, but remember links will have the underline (unless you've styled it otherwise) so the underscore will be insignificant in human interpretation - the other side of this coin is that it may be typed incorrectly if someone attempts to manually enter the URL/URI.
However there *is* a solution for you - but you'll have to work for it. :-)
for(y=1;y<x-i;y++){
output += "../";
}
var textonly = bits[i];
textonly.replace(/\%20/, " ");
output += bits[i] + "/\">" + textonly + "</a> > ";
You store bits[i] in a new variable, use the new variable to replace the %20 with new spaces, then put the new variable in the visible portion of the link, allowing the link itself to maintain the encode characters. Untested, there's your work. :-)