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
;
}
// 调用方法
alert(GetQueryString(
"参数名1"
));
alert(GetQueryString(
"参数名2"
));
alert(GetQueryString(
"参数名3"
));Cases:
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!
Reference: http://www.cnblogs.com/fishtreeyu/archive/2011/02/27/1966178.html
JS Get URL Multiple parameters