How to transfer and obtain parameters in the address bar of an HTML page _ Javascript tutorial

Source: Internet
Author: User
Javscript: How to pass and obtain parameters in the address bar of an HTML page. we know in the Javascript tutorial that the asp program on the server can accept parameters from the form on the html page, can I pass parameters to an html page, that is, add a question mark after html? The answer is yes.

The following is an implementation method of javascript. This function obtains parameters through the delimiter in window. location. href.

With this function, you can pass parameters between pages.

The following is a reference clip:
/*
* Function: obtain parameters from href.
* SHref: http://www.yesky.com/arg.htm? Arg1 = d & arg2 = re
* SArgName: arg1, arg2
* Return: the value of arg. d, re
*/
Function GetArgsFromHref (sHref, sArgName)
{
Var args = sHref. split ("? ");
Var retval = "";
If (args [0] = sHref)/* the parameter is blank */
{
Return retval;/* No processing required */
}
Var str = args [1];
Args = str. split ("&");
For (var I = 0; I <args. length; I ++)
{
Str = args [I];
Var arg = str. split ("= ");
If (arg. length <= 1) continue;
If (arg [0] = sArgName) retval = arg [1];
}
Return retval;
}

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.