Home>
/**
* Get address bar parameters
*
* @example geturlstring ("id")
*
* @desc call with judgment,Guarantee that the program will not go wrong
* var myurl=geturlstring ("id");
* if (myurl!=null&&myurl.tostring (). length>1) {
* alert (geturlstring ("id"));
*}
*
* @param string param to get the parameter name in the address bar
* @return string value
* @type string
*
* @name geturlstring ()
*
* /
function geturlstring (param) {
 var svalue=location.search.match (new regexp ("[\?\&]" + m + "= ([^ \ &] *) (\&?)", "i")) ;
 return svalue?decodeuri (svalue [1]):decodeuri (svalue);
}

Make such a judgment when calling,If you do n’t pass parameters,For example, your address is abc.html without parameters,Sometimes forcing the output of the call results in an error

window.onload=function () {
 var myurl=getparm ("id");
 if (myurl!=null&&myurl.tostring (). length>1) {
 alert (getparm ("id"));
 }
}

This will not give an error!

Note:ecmascript v3 has removed the unescape () function from the standard and opposes its use,So you should use decodeuri () and decodeuricomponent () instead.

  • Previous Two methods to achieve IE browser compatible placeholder effect based on jQuery
  • Next __proto__ and prototype in javascript