如何禁用浏览器后退按钮javascript? [英] How to disable browser back button javascript?

查看:137
本文介绍了如何禁用浏览器后退按钮javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序本身中有后退按钮。单击浏览器后退按钮时,将转到错误的页面。所以我需要禁用浏览器后退按钮。

请给我一些关于我的问题的建议。



我尝试了什么:



我试过以下代码。但它只是刷新当前的URL。



$(文件).ready(function(){

window.history.forward(1 );

});

I am having back button in the application itself. While clicking the browser back button it will take me to the wrong pages. So i need to disable the browser back button.
Kindly give me some suggestion to my issue.

What I have tried:

I have tried the following code. But it just refresh the current url.

$(document).ready(function () {
window.history.forward(1);
});

推荐答案

(文件).ready(function(){

窗口。 history.forward(1);

});
(document).ready(function () {
window.history.forward(1);
});


禁用后退按钮无法正常工作的原因有很多。你最好的选择是警告用户:



There are numerous reasons why disabling the back button will not really work. Your best bet is to warn the user:

window.onbeforeunload = function() { return "Your work will be lost."; };





此页面列出了许多可以尝试禁用后退按钮的方法,但没有一种方法可以保证:



http://www.irt.org/script/311.htm



This page does list a number of ways you could try to disable the back button, but none are guaranteed:

http://www.irt.org/script/311.htm


引用:

所以我需要禁用浏览器后退按钮。

So i need to disable the browser back button.



简答:你没有。

后退按钮是客户端功能的一部分,出于安全原因无法劫持它。我想你必须找到另一种方法来做你想做的事。


Short answer: you don't.
The back button is part of client side functionalities and can't hijack it for security reasons. I guess you have to find another way to do what you want.


这篇关于如何禁用浏览器后退按钮javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆