if window.location == index (homepage)

889 views Asked by At

I wanna do a jquery action on every site except the homepage (index).
I can not find out how to setup the if-statement with window.location
thanks for your help

2

There are 2 answers

2
Tobey On

This should do what you are looking for as the pathname will be a single / if you are at the home page in MVC. I am not sure about webforms but would assume the same if not it would be the page name such as /Default.aspx.

(function selfRunning() {
if (window.location.pathname.length > 1) {
    alert(window.location.pathname);
}

})();

2
Matej Đaković On

You can do:
if(window.location.pathname != "{ do something }") { //run home page jquery. }

But if prefer PHP like
<?php if ( !is_home() ) { ?> ==== jquery code here ===== <?php } ?>

Good luck!! :)