JavaScript gets URL parameter (querystring)

Source: Internet
Author: User

A <script>
Urlinfo=window.location.href; Gets the URL of the current page
len=urlinfo.length;//gets the length of the URL
Offset=urlinfo.indexof ("?"); /sets the position at which the parameter string starts
NEWSIDINFO=URLINFO.SUBSTR (Offset,len)//Fetch parameter string This will get a string like "id=1"
Newsids=newsidinfo.split ("=");//To split the obtained argument string by "="
newsid=newsids[1];//get the parameter value
Alert ("The parameter value you want to pass is" +newsid);
</script>

Two A better way:
Declare a querystring function
<script type= "Text/javascript" >
Request = {
Querystring:function (item) {
var svalue = Location.search.match (New RegExp ("[/?/&]" + Item + "= ([^/&]*) (/&?)", "I"));
Return svalue? SVALUE[1]: svalue;
}
}
</script>

When used like Java call on the line:
<script type= "Text/javascript" >
document.write (Request.QueryString ("name"));
</script>

Turn from: http://hi.baidu.com/yizusong/blog/item/8f8c042e5c505f554fc226a8.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.