JS Get URL Pass parameters

Source: Internet
Author: User

JS Get URL Pass parameters

Here is a JavaScript client solution that gets the URL with the questring parameter, which is equivalent to the $_get function of the ASP's request.querystring,php:

<script language= "JavaScript" >functiongetrequest () {varurl = location.search;//gets the URL in the "?" String after the character   varTherequest =NewObject (); if(Url.indexof ("?")! =-1) {      varstr = URL.SUBSTR (1); STRs= Str.split ("&");  for(vari = 0; i < strs.length; i + +) {Therequest[strs[i].split ("=") [0]]= (Strs[i].split ("=") [1]); }   }   returntherequest;}</Script>

Then we get the corresponding parameter value by calling this function:

<script language= "JavaScript" >  varnew  Object ();   = getrequest ();   var  parameter 1, parameter 2, parameter 3, parameter n;   = request[' parameter 1 '];   = request[' parameter 2 '];   = request[' parameter 3 '];   = request[' parameter n ']; </Script>
This gets the URL string with the same name parameter two, the regular analysis method.
function getquerystring (name) {   varnew RegExp ("(^|&)" + name + "= ([^&]*) (&|$)", "I" );    var r = window.location.search.substr (1). Match (reg);    if (r!=nullreturnreturnnull;} Alert (getquerystring ("parameter name 1")),alert (getquerystring ("parameter Name 2")), alert (GetQueryString (" Parameter Name 3 "));
additional parameters to get introduced://Sets or gets the file name or path specified by the object.
alert (window.location.pathname);//Set or get the entire URL as a string.
alert (window.location.href);//Set or get the port number associated with the URL.
alert (window.location.port);//Set or get the protocol portion of the URL.
alert (window.location.protocol);//Set or get the fragment behind the pound sign "#" in the href attribute.
alert (window.location.hash);//Set or get the hostname and port number of the location or URL.
alert (window.location.host);//Set or get the portion of the HREF attribute that follows the question mark.
alert (window.location.search);This article transferred from: http://www.cnblogs.com/gaojun/archive/2013/06/09/3129412.html

JS Get URL Pass parameters

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.