Recently, when I made a page, I needed to use JavaScript to obtain URL parameters. I found that there were too many items on the Internet, and there were too many errors. I was dizzy and wasted a lot of time, I will sum up that it is easy to use and declare that regular expressions are simple, but the compatibility and speed of multiple browsers are not guaranteed, so I use a multi-browser compatible
CopyCode The Code is as follows: <script language = JavaScript>
Function request (paras ){
VaR url = location. href;
VaR parastring = URL. substring (URL. indexof ("? ") + 1, URL. Length). Split ("&");
VaR paraobj = {}
For (I = 0; j = parastring [I]; I ++ ){
Paraobj [J. substring (0, J. indexof ("= ")). tolowercase ()] = J. substring (J. indexof ("=") + 1, J. length );
}
VaR returnvalue = paraobj [paras. tolowercase ()];
If (typeof (returnvalue) = "undefined "){
Return "";
} Else {
Return returnvalue;
}
}
VaR theurl = request ('url ');
VaR theimg = request ('img ');
Document. writeln ("<a href = '" + theurl + "'target = _ blank> </ a> ");
</SCRIPT>
The most important thing is to useCopy codeThe Code is as follows: function request (paras ){
VaR url = location. href;
VaR parastring = URL. substring (URL. indexof ("? ") + 1, URL. Length). Split ("&");
VaR paraobj = {}
For (I = 0; j = parastring [I]; I ++ ){
Paraobj [J. substring (0, J. indexof ("= ")). tolowercase ()] = J. substring (J. indexof ("=") + 1, J. length );
}
VaR returnvalue = paraobj [paras. tolowercase ()];
If (typeof (returnvalue) = "undefined "){
Return "";
} Else {
Return returnvalue;
}
}
This function will be convenient in the future and will not be searched everywhere.