[英]Why browser refresh and close event detection is not working for IE and Safari
I need to call logout function
on the close of browser window gets close. 我需要在浏览器窗口关闭时调用
logout function
来关闭。 It's working fine in Chrome not working in IE and Safari. Chrome在IE和Safari中无法正常运行。
I have tried the following code: 我尝试了以下代码:
window.onbeforeunload = function (e) {
// Your logic to prepare for 'Stay on this Page' goes here
var evtobj = window.event ? event : e;
if (evtobj == e) {
//firefox
if (!evtobj.clientY) {
//server call
}
}
else {
//IE
if (evtobj.clientY < 0) {
//server call
}
}
//return "Please click 'Stay on this Page' and we will give you candy";
};
I have tried a few other ways but they didn't work. 我尝试了其他几种方法,但是它们没有用。 Please advise.
请指教。
There is something wrong in your design, you SHOULDN'T rely on a client-side hook to perform logout. 您的设计有问题,您不应依赖客户端挂钩执行注销。 There are one billion of reasons why that event could not be executed.
有十亿个原因导致该事件无法执行。 Just limit the
onbeforeunload
event to execute informational content and not critical actions. 只需限制
onbeforeunload
事件即可执行信息内容,而不是执行关键操作。
By the way: 顺便说说:
beforeunload
event! beforeunload
事件! This creates some issue in IE window.sessionStorage
to make some data last until the user closes the tab window.sessionStorage
使一些数据持续到用户关闭选项卡
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.