जब एंकर पार्ट को बदला जाता है, तो ऑनहैशचेंज इवेंट होता है। जावास्क्रिप्ट में onhashchange ईवेंट को कैसे कार्यान्वित किया जाए, यह जानने के लिए आप निम्न कोड चलाने का प्रयास कर सकते हैं।
उदाहरण
<!DOCTYPE html>
<html>
<body onhashchange="newFunc">
<button onclick="functionChange()">Click to change anchor</button>
<script>
function functionChange() {
location.hash = "about";
var hash = location.hash;
document.write("The anchor part is now: " + hash);
}
// If the achor part is changed
function newFunc() {
alert("Anchor part changed!");
}
</script>
</body>
</html>