有的时候项目中会遇到禁止页面后退的操作,在网上查到了方法,但是不兼容ie8,后来同组的小伙伴找到了一个方法,很好用,所以先记载下来,方便以后在用
if(window.history&&window.history.pushState){
//其他浏览器
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
}else{
//ie8
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";//again because google chrome don't insert first hash into history
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-back-button";}
window.setTimeout(function(){window.location.hash="Again-No-back-button";},1000);
}