Skip to content

Instantly share code, notes, and snippets.

@steepzero-old
Created October 2, 2017 11:20
Show Gist options
  • Save steepzero-old/f3366daaf940da2037e9363f5102a86f to your computer and use it in GitHub Desktop.
Save steepzero-old/f3366daaf940da2037e9363f5102a86f to your computer and use it in GitHub Desktop.
вставка параметра в url
function insertParam(key, value, search)
{
key = encodeURI(key); value = encodeURI(value);
search = search.toString();
if(search=='')
search = document.location.search;
if(search[0]=="?")
search = search.substr(1);
var kvp = [];
if(search.search("&")==-1 && search!='')
kvp = [search];
else if(search=='')
kvp = [];
else
kvp = search.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('=');}
return kvp.join('&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment