Javascript examples for DOM Event:Element Event Attribute
The onhashchange event occurs when the URL anchor is about to change.
Bubbles | Yes |
---|---|
Cancelable | No |
Supported HTML tags: | <body> |
<!DOCTYPE html> <html> <body> <button onclick="changePart()">Try it</button> <p id="demo"></p> <script> function changePart() {/*from ww w . j a va2 s . c o m*/ location.hash = "newAnchor"; var x = location.hash; document.getElementById("demo").innerHTML = "The anchor part is now: " + x; } document.getElementsByTagName("BODY")[0].onhashchange = function() {myFunction()}; function myFunction() { console.log("The anchor part has changed!"); } </script> </body> </html>