d-_-b
d-_-b

Reputation: 23191

if (window.location.hash !== "#search")

Is there anything wrong with this syntax? This doesn't seem to work for me, even though if I alert the hash-tag and it matches with my if statement.

my code:

if(window.location.hash) { 
   var thehash = window.location.hash;
   if (thehash !== "#search"){

      alert(thehash); // returns "#search"

      thehash = thehash.replace(/#/g, '/');
      window.location.replace("http://url.com/" + thehash + "/");
   }
}

Why does this still redirect urls containing #search

Upvotes: 1

Views: 3042

Answers (1)

keune
keune

Reputation: 5795

You need to return false after alert, so it won't run the rest of your function

Upvotes: 4

Related Questions