Use JS to get parameters in HTML Web pages.

Source: Internet
Author: User

Use JS to get parameters in HTML Web pages.
We know that HTML pages are executed on the client side, so that the parameters must be obtained using client script (such as JavaScript), which differs from the server-side script fetching parameters.
The following JS code to get HTML page shape such as "Test.html?foo=mytest&program=flash" "?" After all the parameters.

<script language=javascript>
<!--
var hrefstr,pos,parastr;
Hrefstr = window.location.href;
pos = Hrefstr.indexof ("?");
Parastr = hrefstr.substring (pos+1);
if (pos>0) {
document.write ("All Parameters:" +PARASTR);
} else {
document.write ("no parameters");
}
-->
</script>



The following JS code can be more detailed to get an HTML page of a parameter

<script language=javascript>
<!--
function Getparastr (strname) {
var hrefstr,pos,parastr,para,tempstr;
Hrefstr = window.location.href;
pos = Hrefstr.indexof ("?")
Parastr = hrefstr.substring (pos+1);

Para = Parastr.split ("&");
Tempstr= "";
for (i=0;i<para.length;i++)
{
TempStr = Para[i];
pos = tempstr.indexof ("=");
if (tempstr.substring (0,pos) = = strname) {
Return tempstr.substring (pos+1);
}
}
return null;
}
Get program Parameters
var programstr = getparastr ("program");
document.write (PROGRAMSTR);
-->
</script>

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.