javascript “window.history.forward(1);”不工作

发布于 2024-10-09 15:20:42 字数 342 浏览 8 评论 0原文

我试图阻止后退按钮在我的 asp.net mvc 页面之一上工作。 我读过一些地方,如果我输入“window.history.forward(1);”在我的页面中,它将阻止后退按钮在给定页面上工作。 这就是我在我的页面中所做的:

<script type="text/javascript">
        $(document).ready(function () {
            window.history.forward(1);
        });
    </script>

它似乎不起作用。我是否使用了错误的方法或者这种方法是错误的?谢谢。

I'm trying to prevent the back button from working on one of my asp.net mvc pages.
I've read a couple of places that if i put "window.history.forward(1);" in my page it will prevent the back button from working on a given page.
This is what I did in my page:

<script type="text/javascript">
        $(document).ready(function () {
            window.history.forward(1);
        });
    </script>

It doesn't seem to be working. Am I using this incorrectly or is this approach wrong? thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

黎夕旧梦 2024-10-16 15:20:42

我看到这个技巧的使用方法是在您不希望后退按钮起作用的页面之前的每个页面上放置 history.forward() ,然后每次用户点击后退时按钮会将它们转发回原来的位置。常见用途是防止其他人在完成操作后返回页面(通常以给定的线性顺序)。例如,有时这会用在银行网站的登录序列中。

据我所知,没有办法真正禁用后退按钮。有时,人们通过在新窗口中打开页面来解决此问题,该窗口不会有之前页面的历史记录,因此无需返回。其他人只是在返回之前显示一条警告消息,通知用户他们可能会丢失未保存的数据(如果这是主要问题)。

也就是说,也许这会对您有所帮助: http://viralpatel.net/blogs /disable-back-button-browser-javascript/

The way I've seen this trick used is to put history.forward() on every page before the page where you don't want the back button to work, then every time the user hits the back button it forwards them back to where they were. The common use is to prevent others from returning to a page (usually in a given, linear sequence) once they have progressed. This is sometimes used in the sign-in sequence for banking websites, for example.

As far as I know, there is no way to actually disable the back button. Sometimes people get around this by opening the page in a new window, which will not have a history of pages preceding it, and thus nothing to go back to. Others simply display a warning message before going back to inform a user that they may lose unsaved data, if that is the main concern.

That said, maybe this will help you: http://viralpatel.net/blogs/disable-back-button-browser-javascript/

錯遇了你 2024-10-16 15:20:42

或许:...

<script type="text/javascript">
   function disableBackButton()
   {
     window.history.forward();
   }
   setTimeout("disableBackButton()", 0);
    $(document).ready(function () {
       disableBackButton();
    });
</script>

maybe:...

<script type="text/javascript">
   function disableBackButton()
   {
     window.history.forward();
   }
   setTimeout("disableBackButton()", 0);
    $(document).ready(function () {
       disableBackButton();
    });
</script>
最终幸福 2024-10-16 15:20:42

在您不希望后退按钮起作用的页面上使用。

window.history.forward(1);

Use on the page in which you don't want back button to work.

window.history.forward(1);

醉南桥 2024-10-16 15:20:42

这对我有用...希望对您有帮助..

<script type="text/javascript">
    window.history.forward();
    function noBack(){ 
    window.history.forward();
     }
</script>   

 $(document).ready(function() {
            noBack();
}); 

This is working for me... Hope it helpful for you..

<script type="text/javascript">
    window.history.forward();
    function noBack(){ 
    window.history.forward();
     }
</script>   

 $(document).ready(function() {
            noBack();
}); 
傲鸠 2024-10-16 15:20:42

您可以使用

history.go(index)
index =0 //for the current page.
index>0 //e.g 1,2 for forward navigation
index<0 //e.g -1,-2 for backward navigation

history.go(-2)

You can use

history.go(index)
index =0 //for the current page.
index>0 //e.g 1,2 for forward navigation
index<0 //e.g -1,-2 for backward navigation

history.go(-2)
挽清梦 2024-10-16 15:20:42
<SCRIPT type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }
</SCRIPT>

并在html Body标签中写入以下代码。

<body  onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload=" " > 

试试这个,它对我有用。

<SCRIPT type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }
</SCRIPT>

And in html Body tag write the following code.

<body  onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload=" " > 

Try this, it worked for me.

终弃我 2024-10-16 15:20:42

不确定这是否相关,但我发现了它,可能值得一试:

<script type="text/javascript">
    function preventBack() {
        window.history.forward();
    }
    setTimeout("preventBack()", 0);
    window.onunload = function() {
        null
    };
</script>

Not sure if this is relevant but I found it and it might be worth a try:

<script type="text/javascript">
    function preventBack() {
        window.history.forward();
    }
    setTimeout("preventBack()", 0);
    window.onunload = function() {
        null
    };
</script>
心是晴朗的。 2024-10-16 15:20:42
       <script>
            function preventBack() {
                window.history.forward();
            }

            setTimeout("preventBack()", 0);

            window.onunload = function () {
                null
            };
        </script>
       <script>
            function preventBack() {
                window.history.forward();
            }

            setTimeout("preventBack()", 0);

            window.onunload = function () {
                null
            };
        </script>
与他有关 2024-10-16 15:20:42
window.history.forward();
function noBack()
{ 
    window.history.forward();
}

function setit() {
    noBack();
}
window.history.forward();
function noBack()
{ 
    window.history.forward();
}

function setit() {
    noBack();
}
挽心 2024-10-16 15:20:42
   <script>
        function preventBack() {
            window.history.forward();
        }

        setTimeout("preventBack()", 0);

        window.onunload = function () {
            null
        };
    </script>

该代码需要位于前面的页面以及您需要它运行的页面上

   <script>
        function preventBack() {
            window.history.forward();
        }

        setTimeout("preventBack()", 0);

        window.onunload = function () {
            null
        };
    </script>

The code needs to be on the page infront as well as the page you require for it to work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文