How to get the Address bar parameters using JS (super Simple)
Method One: Use regular expressions to get the address bar parameters: (highly recommended, both practical and convenient!) )
function getquerystring (name) {varReg =NewREGEXP ("(^|&)"+ name +"= ([^&]*) (&|$)"); varR = Window.location.search.substr (1). Match (REG); if(r!=NULL)returnUnescape (r[2]);return NULL;} //Calling MethodsAlert (GetQueryString ("Parameter name 1"); alert (GetQueryString ("Parameter Name 2"); alert (GetQueryString ("Parameter name 3"));
Here's an example:
If the Address bar URL is: abc.html?id=123&url=http://www.maidq.com
So, but you use the above method to invoke: Alert (getquerystring ("url"));
A dialog box pops up: the content is http://www.maidq.com
If using: Alert (getquerystring ("id")), then the popup content is 123;
Of course, if you do not pass parameters, such as your address is abc.html back no parameters, the force output call results sometimes error:
So we have to add a judgment to determine if the argument we requested is empty, first assign the value to a variable:
var myurl=getquerystring ("url"); if (Myurl! =null && myurl.tostring () .length>1) { alert (getquerystring ( "URL"));
This will not be an error!
URL Get parameter value