就是让这两个前进和后退点了也没反应,不让页面回退和前进。完全失效
用js location.replace跳转不会出现历史记录,示例如下,11.html和22.html内容如下面的,点击后不会有历史记录,无法回退。有帮助麻烦点个采纳【本回答右上角】,谢谢~~
<a href="11.html">11.html</a>
<br /><a href="22.html">22.html</a>
<script src="https://g.csdnimg.cn/??lib/jquery/1.12.4/jquery.min.js"></script>
<script>
$('a').click(function () {
// location.replace(this.href);
return false;
});
</script>
window.addEventListener(
"popstate",
function(e) {
this.history.forward();
console.log(e);
},
false
);
1在页面的html里加入一段js,记住引入jquery文件
$(function() {
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.history.pushState('forward', null, '#');
window.history.forward(1);
});
}
window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
window.history.forward(1);
})
2跳转页面使用window.location.replace()方法跳转,让历史记录一直为一个记录;
3跳转按钮的编写标签千万不能使用a标签,不然会产生跳转前的历史记录,这样浏览器的自带的前进与后退功能不会失效。