如何在登录后禁用浏览器后退按钮 [英] How Do I Disable Browser Back Button After Login

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

问题描述

现在我正在开发Web应用程序。现在我的问题是我需要在登录到应用程序后禁用浏览器后退按钮。现在,如果我点击浏览器的后退按钮,它将再次重定向到登录页面。我需要禁用后退按钮。我正在使用下面的javascript代码,但它正在使用chrome和firefox浏览器但不支持IE浏览器。

Right now i am working on web application. Now my problem is i need to disable browser back button after login into application. right now if i clicked on back button of browser it is redirect to login page again. i need to disable back button. i am using below javascript code but it is working both chrome and firefox browser but not support IE Browser.

<script type = "text/javascript" >
          history.pushState(null, null, 'pagename');
          window.addEventListener('popstate', function (event) {
              history.pushState(null, null, 'pagename');
      });

     </script>



你能不能帮我一下。


Could you please help me on the same.

推荐答案

不要......

浏览器是最终用户的私有财产。你所拥有的只是浏览器的内部框 - 称为窗口...

设计你的应用程序,使浏览器的后退和前进按钮不会产生问题......

您可以登录您已经登录的登录页面(某种状态)并重定向到推荐人页面...

再次不要乱用浏览器,你是在那里的客人,如果你表现得不好,你将被扔掉......
Do not...
The browser is the private property of the end-user. All you have is the inside box of the browser - called window...
Design your application in such way that back and forward buttons of the browser will not create a problem...
You maybe can check in your login page that you already logged in (some kind of state) and redirect to the referrer page...
Again do not mess with the browser, you are a guest there and you will be thrown away if you behave not nice...


我建​​议在登录时检查 Session Page。



如果会话存在,则重定向到 Home 或某些登陆页面根据您网站的逻辑。
I would suggest to check for Session on Login Page.

If Session exists, then redirect to Home or some Landing page according to your website's logic.


在页面上,您的页面在登录后重定向,将此javascript代码简单地放在设计页面上,我使用此代码和它总是为我工作。





function disableBackButton(){

window.history.forward();

}




谢谢
on the page , where your page redirected after login, put this javascript code simple on design page, I use this code and it always work for me.


function disableBackButton() {
window.history.forward();
}


Thanks


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

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