JS gets the values in the page URL

Source: Internet
Author: User

First, through the window.location to obtain the parameters

1. Get the full URL of the page

url = window.location.href;

2. Get the domain name of the page

host = Window.location.host;

Host2=document.domain;

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/315302/201612/315302-20161207103219632-33294946. PNG "style=" margin:0px;padding:0px;border:0px; "/>

Application Scenario: page jump, development environment and test environment domain name is different, so need to dynamically get the URL after stitching jump.

Second, JavaScript is getting the parameters in the URL 1, through the substr with split get

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

Regular gets the parameter     function url_request (strName) in the URL  {    var  strhref = document.location.tostring ();    var intpos =  Strhref.indexof ("?");     var strright = strhref.substr (intpos + 1);  //========== Get to the right of the parameter section     var arrtmp = strright.split ("&");  //============= & Split Group     for  (var i = 0; i < arrtmp.length;  i++)  //=========== Loop array     {        var  dintpos = arrtmp[i].indexof ("=");        var  Paraname = arrtmp[i].substr (0, dintpos);         var  paradata = arrtmp[i].substr (dintpos + 1);         if (Paraname.touppercase ()  == strname.touppercase ())  {             return paraData;        }     }    return  "";     }

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

Use:

var pbtradeid=url_request ("TradeID");
2. Get "update20170503" through split

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

Function getquerystring (Str, key)  {    if (str)  {         var querystring = str.split ('? ') [1] | |   ';         var arr = querystring.split (' & ')  | |  [];        for (var i = 0; i<arr.length;  i++)  {            var keystring  = decodeuricomponent (arr[i].split (' = ') [0]);             var valuestring = decodeuricomponent (arr[i].split (' = ') [1]);             if (key === keystring)  {                 return valueString;             }        }         return;    } else {         return;    }}getquerystring (location.search,  ' pageId ');

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>


JS gets the values in the page URL

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.