js获取url hash,代码为
window.location.hash
那要监听hash变化的代码呢?如下
if( ("onhashchange" in window) && ((typeof document.documentMode==="undefined") || document.documentMode==8)) { window.onhashchange = hashChanged; } else { alert("浏览器不支持onhashchange事件"); } function hashChanged(){ alert("hash产生了变化") }
以上就是【js获取url的hash及监听hash变化】的全部内容了,欢迎留言评论进行交流!