Javascript examples for DOM Event:addEventListener
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() {// w w w. j a v a 2 s. c om location.hash = "newAnchor"; var x = location.hash; document.getElementById("demo").innerHTML = "The anchor part is now: " + x; } window.addEventListener("hashchange", myFunction); function myFunction() { console.log("The anchor part has changed!"); } </script> </body> </html>