<!DOCTYPE html>
<html>
<body>
<p>Use the HTML DOM to assign an "onhashchange" event to a body element.</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;
}
document.getElementsByTagName("BODY")[0].onhashchange = function() {myFunction()};
function myFunction() {
alert("The anchor part has changed!");
}
</script>
</body>
</html>