<html>
<body>
<p>This example uses the addEventListener() method to attach a "hashchange" event to the window object.</p>
<p>Click the button to change the anchor part of the current URL to #part5</p>
<button onclick="changePart()">Try it</button>
<p id="demo"></p>
<script>
// Using the location.hash property to change the anchor part
function changePart() {
location.hash = "part5";
var x = location.hash;
document.getElementById("demo").innerHTML = "The anchor part is now: " + x;
}
window.addEventListener("hashchange", myFunction);
function myFunction() {
alert("The anchor part has changed!");
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onhashchange_addeventlistener by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:02:56 GMT -->
</html>