Link to home
Start Free TrialLog in
Avatar of Refael
RefaelFlag for United States of America

asked on

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

SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Refael

ASKER

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?
Avatar of Refael

ASKER

Read my previous comment. Thank you guys!
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.