31
rated 0 times
[
36]
[
5]
/ answers: 1 / hits: 21714
/ 13 Years ago, sun, february 5, 2012, 12:00:00
#&q=car&category=Car%20Audio%2CAccessories&brand=
I borrowed a this function from a previous question asked on SO:
function insertParam(key, value)
{
key = escape(key); value = escape(value);
var kvp = document.location.hash.substr(1).split('&');
var i=kvp.length; var x; while(i--)
{
x = kvp[i].split('=');
if (x[0]==key)
{
x[1] = value;
kvp[i] = x.join('=');
break;
}
}
if(i<0) {kvp[kvp.length] = [key,value].join('=');}
//this will reload the page, it's likely better to store this until finished
document.location.hash = kvp.join('&');
}
I use it like this:
insertParam(category,xy);
insertParam(brand,zy);
My problem is it is decoding comma's to %2C. I know I can handle the characters on the server side, but how can I make it look pretty with javascript? By pretty I mean replace %2c with a comma.
More From » javascript