【问题标题】:Logout webpage when click on refresh button单击刷新按钮时注销网页
【发布时间】:2014-09-01 12:20:50
【问题描述】:

我正在开发一个网站。当有人尝试刷新页面时,我需要注销页面。

单击f5 进行刷新时,我获得了注销代码,并且我在页面上获得了禁用right click 的代码。但是当我按下刷新按钮时,我不知道如何防止浏览器的刷新按钮或注销。我搜索了很多网站。但没有得到答案。

F5 键的密码是

function fkey(e){
    e = e || window.event;
   if( wasPressed ) return; 

    if (e.keyCode == 116) {
         alert("f5 pressed");
        wasPressed = true;
    }else {
        alert("Window closed");
    }
}

谁能帮我解决刷新按钮的问题?

【问题讨论】:

标签: javascript refresh logout


【解决方案1】:

我认为它会起作用

$("*").keypress(function(e)
{
if (e.keyCode == 116) {
     e.preventDefault();
  }

}); 

【讨论】:

    【解决方案2】:

    试试这个:

    window.onbeforeunload = function(e){
        //call logout process here
    }
    

    onbeforeunload 是一个在窗口即将卸载其资源时触发的事件。文档仍然可见并且事件仍然可以取消,换句话说,每当您刷新或关闭页面时,它都会触发一个事件“onbeforeunload”。当此事件返回非空值时,将提示用户确认页面卸载。在大多数浏览器中,事件的返回值都会显示在这个对话框中。

    参考:https://developer.mozilla.org/en-US/docs/WindowEventHandlers.onbeforeunload

    【讨论】:

      【解决方案3】:
      window.onbeforeunload = function(e){
          //call logout process here
      }
      

      OnBeforeUnload 上的任何自定义声明都不会执行,因为从代码中删除了支持。因此,上述解决方案不适用于 Chrome。 相反,使用 HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

      【讨论】:

        猜你喜欢
        • 2017-10-16
        • 2014-04-10
        • 1970-01-01
        • 2013-10-10
        • 2015-07-05
        • 2016-11-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多