JS-在本页面禁止页面返回

这个问题是最近遇到的

解决方案我百度的并测试有效

// 如果你希望用户不用有返回功能 可缩写如下 或使用location.replace('url')跳转链接

history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
	history.pushState(null, null, document.URL);
});

注:上面的代码是禁止页面返回,其中document.URL可以指定页面的链接来跳转  

猜你喜欢

转载自www.cnblogs.com/liuqingxia/p/11616981.html