简体   繁体   中英

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

您需要在alertreturn false ,因此它不会运行您的其余功能

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM