JS URL parameters get and set and delete

Source: Internet
Author: User

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

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.