Skip to main content

onhashchange

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
if ("onhashchange" in window) {
alert("该浏览器支持 hashchange 事件!");
}
function locationHashChanged() {
if (location.hash === "#somecoolfeature") {
// somecoolfeature();
alert(1)
}
}
window.onhashchange = locationHashChanged;
</script>
</head>
<body>
<a href="#somecoolfeature">122121</a>
<!-- <div id="box"></div> -->
</body>
</html>