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
Asked
Active
Viewed 828 times
-1

Corrado
- 11
- 1
2 Answers
0
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!! :)

Matej Đaković
- 860
- 4
- 22
-
What would "do something" look like if i want to target the index of www.exmaple.com. i testet "www.example.com" and "http://www.example.com/index.php" nothing worked. i can´t use php because it´s blocked in our cms. my code looks like this `if ( $(window).width() > 1404 && (window.location.pathname != "http://www.example.com/index.php")) { do something } ` – Corrado Nov 21 '14 at 16:57
-
..hm..how blocked? which CMS you use? :) – Matej Đaković Nov 21 '14 at 17:23
0
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);
}
})();

Tobey
- 13
- 3
-
yeah this might solve the index problem but 1.) how can i check for specific pages or 2.) pages which contain a specific keyword in the url ? an answer to this two questions would be nice :-) – Corrado Nov 24 '14 at 08:40
-
pathname is a string so you can use contains('value') or just look to see if pathname == '/yourPage'; remember the home page in MVC will always just be '/' for the pathname. – Tobey Nov 24 '14 at 21:21