禁止html页面返回上一层

两种方式:

// 方式一  触发返回上一层页面事件,只会重新加载当前页面
window.addEventListener('pageshow', function(e) {
    if (e.persisted) {
        location.reload();
    }
})

// 方式二 不会出现刷新效果
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function(e) {
    history.pushState(null, null, document.URL);
})

// 两种方式可以同时使用

 

posted @ 2019-11-12 14:22  aaronthon  阅读(1219)  评论(0编辑  收藏  举报