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
if window.location == index (homepage)
980 Views Asked by Corrado At
2
There are 2 best solutions below
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);
}
})();
Related Questions in IF-STATEMENT
- If...Then...Else Visual Basic 2012
- Why does compiler recognize while(true) at compile time but not if(true)
- Swift 2 - Pattern matching in "if"
- How to get a text to display on vba when a button is pressed?
- PHP statements with <<<EOF string
- Convert string to variable in PHP
- Are the conditional statements if(true) and if(false) evaluated at compile time in java?
- Compare strings using ==
- SQL Several Count
- how to get user to pick inputs Java
- WHERE Clause in SQL statement with 2 conditions
- PHP: most efficient way of structuring IF clauses
- Python - Why is my else statement being ignored in this piece of code?
- Multiple conditions in Java
- C program treats an if statement as false when it is in fact true
Related Questions in INDEXING
- Why does mysql stop using indexes when date ranges are added to the query?
- MySQL: Using natural primary index or adding surrogate when tables are given
- How does MongoDB process unsupported languages?
- Error in indicies while unsetting Sessions
- How to index a field with mongodb-erlang
- How to force use of indices in MongoDB?
- Hint indexes to mysql on Join
- Lucene get all non deleted document from index file
- Querydsl generated sql query wrong sql type (nvarchar instead of varchar)
- Numpy Indexing: Get every second coloumn for each even row
- Simpler, safer string manipulation Python
- Understanding "ValueError: need more than 1 value to unpack" w/without enumerate()
- Poor performance with mongo array index
- Is it possible to skip IndexRebuilder in the startup process of mongodb 2.6?
- Does PostgreSQL self join ignore indexes?
Related Questions in WINDOW.LOCATION
- window.location is not working javascript
- use parameters in window.location.replace
- How to find current page url (like "index.html")?
- Attach a parameter from Angular after a path in window.location
- Refresh an open window that was opened with window.open when the url hash changes
- Add two possible paths with "window.location.href " under the same condition
- if window.location == index (homepage)
- C# - Changing Window Address when making an AJAX Call
- setInterval breaks on window.locaion / window.open
- Dynamically sorting the table along with other few selection criteria via javascript and php
- windows.location.href throws error on IE10 using vbscript
- ie vs chrome window.location.href and <base> tag
- Series of Ajax request doesn't wait for finish
- Using JS in PHP Variable
- Tidying Javascript, Catching and manipulating URLs
Related Questions in EXCEPT
- LINQ Except/Distinct based on few columns only, to not add duplicates
- Python: Multiple try except blocks in one?
- MySQL except clause doesnt work
- How to use a column list in a database trigger on SAP HANA
- Selecting similar videos except for current one using MySQL
- Python - Determine if an exception was raised in a function
- What is the analogue of EXCEPT clause in SQL in Pandas?
- Invalid syntax for except ValueError
- Python empty list Exception
- except script error - extra characters after close-quote while executing
- if window.location == index (homepage)
- MDX - Calculated Member with EXCEPT will not roll-up at all?
- python try except in socket not working
- How do you use try except for library specific errors?
- Except Finally - Operator
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
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!! :)