如何禁用浏览器前进按钮,我有禁用后退的脚本

how to disable the browser forward button and i have script for disable the back...?

本文关键字:脚本 浏览器 何禁用 按钮      更新时间:2023-09-26

下面的代码用于禁用浏览器中的后退按钮。

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>

我不能为前进按钮做这件事。

在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>

希望这有帮助