Yevgen Yevgen - 2 years ago 395
Javascript Question

JavaScript test if url does NOT contain some text

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('RecordID') > -1){
alert('URL shoudl nto have "text" in it');

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

Answer Source
if (document.location.href.indexOf('RecordID') === -1){ 
    alert('URL shoudl nto have "text" in it');

Maybe you should learn Javascript a bit...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download