以下代码用于禁用浏览器中的后退按钮。
onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload=""
<script type = "text/javascript" >
window.history.forward();
function noBack() {
window.history.forward();
window.onload = window.history.forward(0);
window.onbeforeunload = function () { return "You work will be lost."; };
}
</script>
我无法为前进按钮执行此操作。
答案 0 :(得分:0)
在javascript中试用此代码
<script type = 'text/javascript' >
function changeHashOnLoad() {
window.location.href += '#';
setTimeout('changeHashAgain()', '50');
}
function changeHashAgain() {
window.location.href += '1';
}
var storedHash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != storedHash) {
window.location.hash = storedHash;
}
}, 50);
window.onload=changeHashOnLoad;
</script>
替代方法
<SCRIPT type='text/javascript'>
window.history.forward();
function noBack() {window.history.forward(); }
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack()}
window.onunload=function(){void(0)}
</SCRIPT>
希望这有帮助