禁用浏览器前进后退功能

禁用浏览器前进后退功能
这里使用的是Vue

// 在 main.js 中添加以下代码
// 禁用浏览器前进后退
window.history.pushState(null, null, window.location.href);
window.addEventListener('popstate', function () {
  window.history.forward(-1);
  window.history.pushState(null, null, window.location.href);
});

// 在每个页面加载完成时执行以下代码
window.history.pushState(null, null, window.location.href);
发布了5 篇原创文章 · 获赞 0 · 访问量 1501

猜你喜欢

转载自blog.csdn.net/MingFeng197/article/details/104683765
今日推荐