Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 16:36:25
Original
1232 people have browsed it

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; 
}
Copy after login
var sname = GetQueryString("name"); 
if(sname!=null) 
{ 
var sname_ = decodeURIComponent(sname); 
alert(sname_); 
}
Copy after login

Test

abcd.html?name=xyz

xyz should pop up

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template