The method of obtaining address bar parameters with JS (super simple)
Method 1: Use regular expressions to obtain address bar parameters: (strongly recommended, both practical and convenient!)
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr( 1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
// call method
alert(GetQueryString("parameter name 1"));
alert(GetQueryString("parameter Name 2"));
alert(GetQueryString("Parameter name 3"));
Here's an example:
If the URL in the address bar is: abc.html?id=123&url=http://www.maidq.com
Well, but you use the above method to call: alert(GetQueryString("url"));
A dialog box will pop up: the content is http://www.maidq.com
If you use: alert(GetQueryString("id")); then the pop-up content is 123;