Javascript DOM HTML Body handle hash change event

Description

Javascript DOM HTML Body handle hash change event

View in separate window

<!DOCTYPE html>
<html>
<body onhashchange="myFunction(event)">
<button onclick="changePart()">Test</button>
<p id="demo"></p>
<script>
// Using the location.hash property to change the anchor part
function changePart() {//from   w  w w  . j a  v  a2 s  .c  om
  location.hash = "part5";
}

function myFunction() {
  document.getElementById("demo").innerHTML = "Previous URL: " + event.oldURL
  + "<br>New URL: " + event.newURL;
}
</script>

</body>
</html>



PreviousNext

Related