Home >Web Front-end >JS Tutorial >js method to get parameters from the page_javascript skills

js method to get parameters from the page_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:37:011256browse

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