Js method to get parameters from the page
- 2020-03-30 03:53:58
- OfStack
This article mainly introduces window.location.search to get the parameters from the page, which is OK after testing
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return (r[2]); return null;
}
var sname = GetQueryString("name");
if(sname!=null)
{
var sname_ = decodeURIComponent(sname);
alert(sname_);
}
test
The abcd. HTML & # 63; Name = xyz
It should pop xyz