Three ways to receive URL parameters in HTML

Source: Internet
Author: User

1. Use Window.location.search to obtain the following parameters

The name of the param parameter

function GetParameter (param)
{
var query = Window.location.search;
var ilen = param.length;
var iStart = query.indexof (param);
if (IStart = =-1)
Return "";
IStart + = Ilen + 1;
var iend = Query.indexof ("&", IStart);
if (iend = =-1)
Return query.substring (IStart);
Return query.substring (IStart, iend);
}

Then call the GetParameter method: var temp = getparameter ("AA");

2. Use Window.location.href to obtain the following parameters

var url=window.location. href;
var aa=url.indexof (' = ');
if (aa = =-1)
Return "";
Url=url.substring (aa+1);
Window.alert (URL);

3. Save the following code as an HTML file: aa.htm, and then open the site:

Enter to display the demo effect and normally receive the value passed by the HTML file.

<script language= "JScript" >
<!-
var locstring=string (WINDOW.DOCUMENT.LOCATION.HREF);
function GetQueryString (str) {
var rs=new RegExp ("(^|)" +str+ "= ([^&]*) (&|$)", "GI"). EXEC (locstring), TMP;
if (TMP=RS) return tmp[2];
Return "without this parameter";
}
Alert ("Journal Number:" +getquerystring ("log_id"));
Alert ("Category number:" +getquerystring ("cat_id"));
Alert ("page number:" +getquerystring ("pages"));
-
</script>

Three ways to receive URL parameters in HTML

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.