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