Forum Moderators: open
I'm trying to use JS to parse the URL of a page and replace characters within it. Specifically, I want to take a URL like this:
http://www.domain.com/classifieds/short_term_rentals-b408.html and populate and print a variable with this:
short+term+rentals Here is what I have:
var string=(location.href);
var getit= new Array();
var getit=string.split("classifieds/");
var result=getit[1];
var filename=result.replace("_","+");
var q=filename.split("-");
document.write(q[0]);
but this is only replacing the *first* underscore in the URL and is printing:
paris+short_term_rentals How can I get it to loop and replace ALL the underscores?
Thanks for any help!