Use JS to set URL parameters

Source: Internet
Author: User
This article is the use of JS set URL parameters of the implementation code for a detailed analysis of the introduction, the need for friends under the reference

//Get the Address bar array of parameters
function Geturlparams () {


var search = Window.location.search;


//Write Data dictionary


var tmparray = search.substr (1, search.length). Split ("&");


var paramsarray = new Array;


if (Tmparray!= null) {


for (var i = 0; i < tmparray.length; i++) {


var reg =/[=|^==]/; Split with =, excluding = =


var Set1 = tmparray[i].replace (Reg, ' & ');


var tmpStr2 = set1.split (' & ');


var array = new Array;


array[tmpstr2[0]] = tmpstr2[1];


Paramsarray.push (array);


        }


    }


//Returns the parameter array


return paramsarray;


}


//Get parameter value based on parameter name
function GetParamValue (name) {


var paramsarray = Geturlparams ();


if (Paramsarray!= null) {


for (var i = 0; i < paramsarray.length; i++) {


for (Var j in Paramsarray[i]) {


if (j = = name) {


return PARAMSARRAY[I][J];


                }


            }


        }


    }


return null;


}

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.