every page but the index

Hello Experts,

This if statement I use to distinguish between the index page (home page) and the inner pages of a website.
So... when the page URL have the "index.php" this code works but it does not work when the someone enter the root URL e..g "mydomain.com". How can I make this code work?

if (window.location.href.indexOf('index') === -1) {}

Open in new window

RefaelAsked:
Who is Participating?
 
skijCommented:
Use this code to make sure that query strings are taken into account:
if (window.location.href.indexOf('index') === -1 && window.location.href.split('?')[0].substr(-1) != '/' ) {alert("Not Home");}

Open in new window

0
 
Rainer JeschorCommented:
Hi,
how about this?
var is_root = ((location.pathname == "/") || (location.pathname == "/index.php")) ;

Open in new window

HTH
Rainer
0
 
RefaelAuthor Commented:
Hello skij, Hello Rainer thank you both!
I decided to go with skij solution only that i think there is missing one "=" so instead of "!=" it should be "!==", right?
0
 
RefaelAuthor Commented:
Read my previous comment. Thank you guys!
0
 
skijCommented:
Refael, thanks for your feedback to my comment.  Both "!=" and will work  "!==" in this instance.  Using "!==" would require the result to be a string only, however in this instance it makes very little or no difference.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.