<script>
$(document).ready(function(e) {
var counter = 0;
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.history.pushState('forward', null, '#');
window.history.forward(1);
//$("#label").html("第" + (++counter) + "次单击后退按钮。");
});
}
window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
window.history.forward(1);
$(document).ready(function(e) {
var counter = 0;
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.history.pushState('forward', null, '#');
window.history.forward(1);
//$("#label").html("第" + (++counter) + "次单击后退按钮。");
});
}
window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
window.history.forward(1);
});
</script>
本文介绍了一种使用JavaScript阻止用户在浏览器中使用后退按钮的方法。通过监听窗口的popstate事件并重新推送历史记录状态,可以有效防止用户直接返回到上一页面。此技巧适用于希望引导用户按特定流程操作的网站。
9081

被折叠的 条评论
为什么被折叠?



