Javascript - To get URLs in JS
This function is used to get values from URL.
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
Eg: URL: http://www.xyz.com?type=test
Output: test
So that we can check through Javascript,
var type = getUrlVars()["type"];
if(type == "test") {
alert(" I am here");
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
Eg: URL: http://www.xyz.com?type=test
Output: test
So that we can check through Javascript,
var type = getUrlVars()["type"];
if(type == "test") {
alert(" I am here");
}
Comments
Post a Comment