繁体   English   中英

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

[英]how to disable the browser forward button and i have script for disable the back…?

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

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>

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM