How to get parameters in url in JavaScript
This article is about how to get parameters in url in JavaScript. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
1. Get the value of the specified url parameter
//get the specified parameter value of the specified url
//name is the parameter name
//url is the specified url address
function GetQueryStringRegExp(name,url) {
var reg = new RegExp("(^|\\?|&) " + name + "=([^&]*)(\\s|&|$)", "i");
if (reg.test(url)) return decodeURIComponent(RegExp.$ 2.replace(/\+/g, " ")); return "";
}
2. Get the value of the specified parameter URL of the current page
//get url value of specified parameter
function GetQueryStringRegExp(name) {
var reg = new RegExp("(^|\\?|&) " + name + "=([^&]*)(\\s|&|$)", "i");
if (reg.test(location.href)) return decodeURIComponent(RegExp.$ 2.replace(/\+/g, " ")); return "";
}
Thank you for reading! About "how to get url parameters in JavaScript" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!