Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  26] [ 4]  / answers: 1 / hits: 31218  / 10 Years ago, tue, june 17, 2014, 12:00:00

I found many option of checking if the URL contains some text but I am trying to do the opposite.



How can I start a function if the URL DOES NOT contain 'text'?



Here is what I started with that does fire the function but only if the url contains it:



if (document.location.href.indexOf('text') > -1){ 
alert('URL should not have text in it');
}


I tried adding a '!' and a 'NOT' in front of the '(document...' but I guess that's not it.


More From » jquery

 Answers
2
if (document.location.href.indexOf('text') === -1){ 
alert('URL should not have text in it');
}

[#70533] Sunday, June 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
joep

Total Points: 32
Total Questions: 97
Total Answers: 104

Location: Wales
Member since Thu, Jul 1, 2021
3 Years ago
;