mercredi 2 mai 2018

An Javascript If statement returns true, though it would have to return false [on hold]

I want my website to create a popup message, if the url contains a specific hash value.

Here is the code:

    <script>
     function getHash(){
      var hash = location.hash.substr(1);
       if (hash = 'Tabone'){
        window.alert(hash);
       }
       else{
        window.alert('nothing');
       }
      }

     getHash();
     </script>

I put this inside the body section. The problem is that it doesn't matter what hash value I put in the url. The popup returns "Tabone" every time. So I think there is something wrong with the If statement. Can somebody help me? What did I wrong?

Aucun commentaire:

Enregistrer un commentaire