禁止html页面返回上一层

阅读 82

2022-08-22

两种方式:

// 方式一  触发返回上一层页面事件,只会重新加载当前页面
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);
})

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

 



精彩评论(0)

0 0 举报