首页 > 技术文章 > 导航跳转,禁止后退

caoxiaokang 2019-02-20 11:46 原文

  
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.history.pushState('forward', null, '#');
window.history.forward(1);
});
}
window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
window.history.forward(1);

当history实体被改变时,popstate事件将会发生; onhashchange()可监听URL的hash部分。

推荐阅读