<!DOCTYPE html>
<html>
<body>
<p>Assign an "onhashchange" 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>
function changePart() {
location.hash = "part5";
var x = location.hash;
document.getElementById("demo").innerHTML = "The anchor part is now: " + x;
}
window.onhashchange = myFunction;
function myFunction() {
alert("The anchor part has changed!");
}
</script>
</body>
</html>