Get address bar parameters such as index.asp?id=xxx&name=xxx in JavaScript
Source: Internet
Author: User
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"];
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