I am using this code to detect the homepage and it works great:
var url= window.location.href;
if(url.split("/").length>3){
alert('You are in the homepage');
}
My problem is that I also need to detect if the url has variables for example:
mysite.com?variable=something
I need to also detect if the url has variables on it too
How can I do this?
Take a look at the window.location docs , the information you want is in location.search
, so a function to check it could just be:
function url_has_vars() {
return location.search != "";
}