Get address bar parameters such as index.asp?id=xxx&name=xxx in JavaScript

Source: Internet
Author: User
Tags return split
JavaScript, like index.asp?id=xxx&name=xxx.

How can I use JavaScript to get the value of ID's name?
Method One:
<script>
function GetValue (name)
{
var Str=window.location.search;
if (str.indexof (name)!=-1)
{
var pos_start=str.indexof (name) +name.length+1;
var pos_end=str.indexof ("&", Pos_start);
if (pos_end==-1)
{
Return str.substring (Pos_start);
}
Else
{
Return str.substring (Pos_start,pos_end)
}
}
Else
{
Return "does not have this name value";
}
}
var strname=prompt ("Please enter the name of the value you want");
Alert (GetValue (strName));
</script>

Method Two:

This is done in the Ewebeditor online editor for you to refer to:
var urlparams = new Array ();
var aparams = document.location.search.substr (1). Split (' & ');
for (i=0 i < aparams.length i++) {
var aparam = aparams.split (' = ');
Urlparams[aparam[0]] = aparam[1];
}

Gets the name parameter passed over
name=urlparams["Name"];

Method Three:
<script type= "Text/javascript" >
Request = {
Querystring:function (item) {
var svalue = Location.search.match (New RegExp ("[\?\&]" + Item + "= ([^\&]*) (\&?)", "I"));
Return svalue? SVALUE[1]: svalue;
}
}
Alert (Request.QueryString ("id"));
</script>


Related Article

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.