Created
October 2, 2017 11:20
-
-
Save steepzero-old/f3366daaf940da2037e9363f5102a86f to your computer and use it in GitHub Desktop.
вставка параметра в url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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