简体   繁体   English

在window.onunload上的KIll用户会话

[英]KIll user session on window.onunload

I want to kill a users session if they back out of a certain page. 如果他们退出某个页面,我想杀死一个用户会话。

The problem is apparently window.onunload does not work in chrome or something to that effect. 问题显然是window.onunload在chrome中无法正常工作或达到这种效果。 Is there a work around for this where I can kill the session ONLY when the user backs out ? 有没有解决的办法,我只能在用户退出时才能终止会话? Right now if the user backs out, it will give them a prompt which offers them the choice of staying on the page or leaving. 现在,如果用户退出,它将给他们一个提示,使他们可以选择停留在页面上还是离开页面。


client side: 客户端:

<a4j:jsFunction 
    name="killUserSession" 
    action="#{sessionController.invalidateSession()}"/>

........... ...........

var warning = true;
window.onbeforeunload = function() { 
  if (warning) {
    return "You have not filled out the required information below.";
  }
}

window.onunload = function(){
    killUserSession();
}

function setOnloadNull(){
    console.log("Setting onload to null");
    var warning = false;
    window.onbeforeunload = null;
}

I check your issue and i found (under chrome) setOnLoadNull is the cause of the issue. 我检查了您的问题,发现(在chrome下) setOnLoadNull是问题的原因。

Demo fails. 演示失败。

But when i disable this method, then the onunload works like a charm. 但是当我禁用此方法时, onunload就像一个魅力。

Demo works. 演示作品。

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

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