Get URL parameters from JavaScript

Source: Internet
Author: User
Tags query
Javascript

There are generally two ways to submit data for a page: Get,post. Post is the so-called form submission, which uses views, and get is submitted by URL.

Get methods generally use background code (such as asp,asp.net) to obtain parameters, the code is very simple: request.querystring["id";

Sometimes need to directly in the foreground to get the URL parameters, to use the JAVASCRIPT,JS did not directly get the URL parameters of the method, then, how do we get the URL parameters js?
Read code Edit Code run effect copy HTML code save code <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> New Document </title>
<meta name= "generator" content= "EditPlus"/>
<meta name= "Author" content= ""/>
<meta name= "keywords" content= ""/>
<meta name= "description" content= ""/>
<script type= "Text/javascript" >
function Geturlparms ()
{
var args=new Object ();
var query=location.search.substring (1);//Get query string
var pairs=query.split ("&");//Break at comma
for (Var i=0;i<pairs.length;i++)
{
var pos=pairs[i].indexof (' = ');//Find Name=value
if (pos==-1) continue;//skipped if not found
var argname=pairs[i].substring (0,pos);//Extract Name
var value=pairs[i].substring (pos+1);//Extract value
Args[argname]=unescape (value);//Save As Property
}
return args;
}
How to use:
var args = new Object ();
args = Geturlparms ();
If you want to find the parameter ArticleID:
var ArticleID = args["ArticleID"];
alert (ArticleID);
If you are looking for a parameter typeid
var typeid = args["typeID"];
alert (typeid);
</script>

<body>

</body>



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.