Add the following code before your code, then it will prepare oldURL and newURL for you.
(function(){
if(!window.HashChangeEvent){
var lastURL=document.URL;
window.addEventListener("hashchange",function(e){
var oldURL=lastURL;
var newURL=document.URL;
lastURL=newURL;
Object.defineProperties(e,{
oldURL:{enumerable:true,configurable:true,value:oldURL},
newURL:{enumerable:true,configurable:true,value:newURL}
});
});
}
}());
本文介绍了一种在浏览器环境中监听URL变化的方法,通过自定义实现hashchange事件来获取旧URL和新URL,适用于不支持原生HashChangeEvent的环境。
768

被折叠的 条评论
为什么被折叠?



