<html>
<body onhashchange="myFunction(event)">
<p>点击按钮将当前 URL 的锚部分(hash)改为 #part5</p>
<p>oldURL 属性返回我们导航离开的文档的 URL。</p>
<p>newURL 属性返回我们要导航到的 URL。</p>
<button onclick="changePart()">试一试</button>
<p><b>注释:</b>Internet Explorer 不支持这些属性。</p>
<p id="demo"></p>
<script>
// 使用 location.hash 属性更改锚点部分
function changePart() {
location.hash = "part5";
}
function myFunction() {
document.getElementById("demo").innerHTML = "Previous URL: " + event.oldURL
+ "<br>New URL: " + event.newURL;
}
</script>
</body>
</html>