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