Copy Code code as follows:
/**
* Get Address bar parameters
*
* @example geturlstring (' id ')
*
* @desc call with the decision to ensure that the program is not wrong
* var myurl = geturlstring (' id ');
* IF (myurl!= null && myurl.tostring (). length > 1) {
* Alert (geturlstring ("id"));
* }
*
* @param String param to get the name of the parameter 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);
}
Call the time unified to do such a judgment, to avoid you do not pass the parameters, such as your address is abc.html after no parameters, that forced output call results sometimes the error
Copy Code code as follows:
Window.onload = function () {
var myurl = getparm ("id");
if (Myurl!= null && myurl.tostring (). length > 1) {
Alert (Getparm ("id"));
}
}
So there won't be an error!
Note: ECMAScript v3 has removed the unescape () function from the standard and objected to its use, so it should be replaced with decodeURI () and decodeURIComponent ().
Do the small partners understand how to use JavaScript to get the address bar parameters, if you have any questions, leave a message.