HTML5 Web page get URL pass parameters

Source: Internet
Author: User

As a front-end, you need to pass parameters to the background to test, but the background is not PHH and not JSP, is not familiar with their own short time can not grasp the language,
For testing convenience, if only simple parameters, non-data flow can be directly to the HTML page through the URL, the relevant code is as follows

<!doctype html>
<meta chareset= "Utf-8" >

<body>
<script>

var paramarr = [];

Gets an array of argument lists, each of which is an object {key: ', Val: '},key is the parameter name, Val is the argument value
function GetParameters () {

var params = Window.location.search;

var paramlist = params.substr (1). Split (' & ');




for (Var i=0;i<paramlist.length;i++) {

var paramkey = paramlist[i].split (' = ') [0];
var paramval = paramlist[i].split (' = ') [1];

var param = {};
Param.key = Paramkey;
Param.val = Paramval;


Paramarr.push (param);
}

return Paramarr;
}


Gets the parameter value corresponding to the specific parameter name
function Getparambyname (name) {

for (Var i=0;i<paramarr.length;i++) {

if (Paramarr[i].key ==name) {

return paramarr[i].val;
}
}

}

GetParameters ();

Here I test the parameter named code, please modify it yourself
Alert (Getparambyname ("Code"));


</script>

</body>

HTML5 Web page get URL pass parameters

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.