Tuesday, 10 September 2013

Remove plus sign (+) in URL query string

Remove plus sign (+) in URL query string

I am trying get the string in the following URL to display on my webpage.
http://example.com?ks4day=Friday+September+13th
I can get it to display on my webpage using the code below, the problem is
the plus signs (+) come through as well.
eg. Friday+September+13th
What I need it to do is replace the plus signs (+) with spaces so it looks
like this:
eg. Friday September 13th
I'm new to this so I'm having some trouble working it out.
Any help would be appreciated.
This is the code i'm using in a .js file
function qs(search_for) {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0 && search_for == parms[i].substring(0,pos)) {
return parms[i].substring(pos+1);;
}
}
return "";
}
This is the code i'm using on my webpage to make it display
<script type="text/javascript">document.write(qs("ks4day"));</script>

No comments:

Post a Comment