JS URL parameters get and set and delete
Gets the value of the URL parameter: name is the parameter name function getquerystring (name) {var reg = new RegExp ("(^|&)" + name + "= ([^&am P;] *) (&|$) "," I "); var r = window.location.search.substr (1). Match (REG); if (r! = null) {return (r[2]); } return null; }//Set URL parameter value, ref parameter name, value new parameter values function Changeurlpar (URL, ref, value) {var str = ""; if (Url.indexof ('? ')! =-1) str = URL.SUBSTR (Url.indexof ('? ') + 1); else return URL + "?" + ref + "=" + value; var returnurl = ""; var setparam = ""; var arr; var modify = "0"; if (Str.indexof (' & ')! =-1) {arr = Str.split (' & '); For (i in arr) {if (arr[i].split (' = ') [0] = = ref) {SetParam = value; Modify = "1"; } else { SetParam = arr[i].split (' = ') [1]; } ReturnUrl = ReturnUrl + arr[i].split (' = ') [0] + "=" + SetParam + "&"; } ReturnUrl = returnurl.substr (0, returnurl.length-1); if (modify = = "0") if (ReturnUrl = = str) ReturnUrl = ReturnUrl + "&" + ref + "=" + value; } else {if (str.indexof (' = ')! =-1) {arr = str.split (' = '); if (arr[0] = = ref) {SetParam = value; Modify = "1"; } else {setparam = arr[1]; } ReturnUrl = arr[0] + "=" + SetParam; if (modify = = "0") if (ReturnUrl = = str) ReturnUrl = ReturnUrl + "&" + ref + "=" + value; } else ReturnUrl = ref + "=" + value; } return url.substr (0, Url.indexof ('? ')) + "?" + ReturnUrl; }//Delete parameter value function delquestr (URL, ref) {var str = ""; if (Url.indexof ('? ')! =-1) {str = URL.SUBSTR (Url.indexof ('? ') + 1); } else {return URL; } var arr = ""; var returnurl = ""; var setparam = ""; if (Str.indexof (' & ')! =-1) {arr = Str.split (' & '); For (I-in arr) {if (arr[i].split (' = ') [0]! = ref) {ReturnUrl = ReturnUrl + arr[ I].split (' = ') [0] + "=" + arr[i].split (' = ') [1] + "&"; }} return Url.substr (0, Url.indexof ('? ')) + "?" + returnurl.substr (0, Returnurl.length-1) ; } else {arr = str.split (' = '); if (arr[0] = = ref) { Return url.substr (0, Url.indexof ('? ')); } else {return URL; } } }
JS URL parameters get and set and delete