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

WBOY
Release: 2016-05-16 16:37:01
Original
1220 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; 
} 

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