When the address bar contains parameters, we can then target the page through Window.location.search to get the parameters and values we need
Copy Code code as follows:
Gets an array of arguments for the address bar
function Geturlparams ()
{
var search = Window.location.search;
Write Data dictionary
var Tmparray = search.substr (1,search.length). Split ("&");
var paramsarray = new Array;
if (Tmparray!= null)
{
for (var i = 0;i<tmparray.length;i++)
{
var reg =/[=|^==]/; Split with =, excluding = =
var Set1 = tmparray[i].replace (Reg, ' & ');
var tmpStr2 = set1.split (' & ');
var array = new Array;
Array[tmpstr2[0]] = tmpstr2[1];
Paramsarray.push (array);
}
}
Returns the array of arguments
return paramsarray;
}
Get parameter values based on parameter names
function GetParamValue (name)
{
var Paramsarray = Geturlparams ();
if (Paramsarray!= null)
{
for (var i = 0; i < paramsarray.length i + +)
{
for (Var j in Paramsarray[i])
{
if (j = = name)
{
return PARAMSARRAY[I][J];
}
}
}
}
return null;
}
Our current page address is http://www.jb51.net/tatame/admin/EditPosts.aspx?opt=1
You can see that the URL contains a parameter
var opt = GetParamValue ("opt");
alert (opt); pop up to 1.
Copy Code code as follows:
/********
Receive Address bar parameters
Key: Parameter name
**********/
function Getquery (key) {
var search = Location.search.slice (1); Gets a get-way submit query string
var arr = search.split ("&");
for (var i = 0; i < arr.length; i++) {
var ar = arr[i].split ("=");
if (ar[0] = = key) {
return ar[1];
}
}
}
Call Getquery (' test ') on the page load the function is good, very practical