JS get url parameter modify URL parameter remove URL parameter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.