禁止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);
})

// 两种方式可以同时使用
原文地址:https://www.cnblogs.com/aaronthon/p/11841592.html