js实现浏览器禁用后退功能(历史记录)
方法一
这种方式,可以消除后退的所有动作。包括 键盘、鼠标手势等产生的后退动作。浏览器的后退按钮可以点击,但是没有后退效果。
<script language="javascript">
//防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
</script>
方法二
页面跳转时采用location.replace(url)。采用这种方式,浏览器的后退按钮变成了灰色,不可以点击。