The code copy is as follows:
/**
* Get the address bar parameters
*
* @example GetUrlString('id')
*
* @desc adds judgment when calling to ensure that the program will not make any errors
* 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 judgments when calling to avoid not passing parameters. For example, if your address is abc.html and there are no parameters after it, then if the forced output of the call result will sometimes be errors.
The code copy is as follows:
window.onload = function() {
var myurl = GetParm("id");
if (myurl != null && myurl.toString().length > 1) {
alert(GetParm("id"));
}
}
This way you won’t report an error!
Note: ECMAScript v3 has removed the unescape() function from the standard and is opposed to using it, so it should be replaced by decodeURI() and decodeURIComponent().
Have you understood how to use JavaScript to get address bar parameters? If you have any questions, leave a message.