The following code is used to get URL parameters.
<script type="text/javascript">
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
</script>
<script type="text/javascript">
var url = window.location.protocol + "//" + window.location.hostname;
</script>
The page with the above code is accessed from a link on another page. Within that link i'm passing in a news item ID and Title. When the page with the above code loads the Title in the URL has %20 in place of all spaces. I've read up on this and found i need to use decodeURI or decodeURIComponent. I've tried to do this in a number of places and alerted the result in the browser but i can't seem to get rid of the %20 from the title within the URL so its obvious i'm not doing it in the right place.
this is my result....
http://PAGE URL HERE/NewsArchive.aspx?Story=New%20site%20launched&ID=17
I believe i somehow need to include a regular expression of /%20/g,"-" in the replace of the parts variable, however i have next to no knowledge of regex.
Could someone let me know what i need to do as i'm drawing a blank. I've seen a number of similar articles but nothing that explains it to my low level of knowledge.
I also post on SharePoint Stack Exchange as this is being used with SharePoint but i haven't had any answers that have worked for me.
Any help appreciated.