Check if the user changes domain vis window onhashchange event - Javascript DOM

Javascript examples for DOM:Event

Description

Check if the user changes domain vis window onhashchange event

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script>
    window.start = function(){/*from w w w .  ja va2s  . c o m*/
        var url = "http://www.yoursite.com";
        if ("onhashchange" in window) {
        console.log("The browser supports the hashchange event!");
        }
        function locationHashChanged() {
        if (location.hash != url) {
            console.log('change url');
        }
        }
        window.onhashchange = locationHashChanged;
        }
    
      </script> 
   </head> 
   <body onload="window.start();">  
   </body>
</html>

Related Tutorials