JQuery Detect If in Homepage and Homepage PLUS url Variables

Using window.location.pathname could work too:

if ( window.location.pathname == '/' ){
    // Index (home) page

} else {
    // Other page
    console.log(window.location.pathname);
}

See MDN info on window.location.pathname.


You can find out if you're on the homepage by comparing href to origin:

window.location.origin == window.location.href

To get the query parameters you can use the answer here: How can I get query string values in JavaScript?


if current url is xxxxx.com something like that, then xxx

if (window.location.href.split('/').pop() === "") { 
    //this is home page
}

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 != "";
}