JS get url parameter modify URL parameter remove URL parameter
function Urlhelper () {var obj= {}; //gets the value of the URL parameter: name is the name of the parameterObj.getquerystring =function (name) {var reg=NewRegExp ("(^|&)" + name + "= ([^&]*) (&|$)", "I"); var r= WINDOW.LOCATION.SEARCH.SUBSTR (1). Match (REG); if(r! =NULL) { return(r[2]); } return NULL; } //set URL parameter values, ref parameter names, value new parameter valuesObj.changeurlpar =function (URL, ref, value) {var str= ""; if(Url.indexof ('? ')! =-1) Str= Url.substr (Url.indexof ('? ') + 1); Else returnURL + "?" + 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; } ElseReturnUrl= ref + "=" +value; } returnUrl.substr (0, Url.indexof ('? ')) + "?" +ReturnUrl; } //Delete parameter valuesObj.delquestr =function (URL, ref) {var str= ""; if(Url.indexof ('? ')! =-1) {str= Url.substr (Url.indexof ('? ') + 1); } Else { returnURL; } 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] + "&"; } } returnUrl.substr (0, Url.indexof ('? ')) + "?" + returnurl.substr (0, Returnurl.length-1); } Else{arr= Str.split (' = ')); if(Arr[0] = =ref) { returnUrl.substr (0, Url.indexof ('? '))); } Else { returnURL; } } } returnobj;}
JS get url parameter modify URL parameter remove URL parameter