Home  >  Article  >  Web Front-end  >  js uses location.search to get the parameters passed by the page_javascript skills

js uses location.search to get the parameters passed by the page_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:36:251176browse

This article mainly introduces how to obtain the parameters from the page through window.location.search. It has been tested and is OK

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

abcd.html?name=xyz

xyz should pop up

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn