To get the parameters of the current page url, you may first think of using window. Location. href or document. Location. href to get results such as http://www.xxx.com /? AA = XX & BB = xx; but what we need is :? AA = XX & BB = xx. In this form, you can use the document. Location. Search attribute.
What if I want to obtain the value of AA after the URL? The common method may be as follows:
Function (PARAM ){
VaR URL = Window. Location. tostring ();
URL = URL. Split ( ' ? ' );
If ( Typeof (URL [ 1 ]) = ' String ' ){
URL = URL [ 1 ]. Split ( ' & ' );
For (I = 0 ; I < URL. length; I ++ )
{
S = URL [I]. Split ( " = " );
If (S [ 0 ] = " Param " ) Return S [ 1 ];
}
}
Return Null ;
}
Use document. Location. Search and regular expression to obtain parameters.CodeMore concise:
Function Getparameter (sprop)
{
VaR Re = New Regexp (sprop + " = ([^ \ &] *) " , " I " );
VaR A = Re. Exec (document. Location. Search );
If ( = Null )
Return Null ;
Return A [ 1 ];
};