下面的代码在IE8中运行良好。
下面是我的代码:
window.onbeforeunload = function () {
return "Are you sure want to LOGOUT the session ?";
};
window.onunload = function () {
parent.logout();
};
但在IE9+中
window.onbeforeunload
起作用了,我收到了警报。
但是window.onunload
不工作。
我还尝试使用Group Policies in Internet Explorer 9
来启用Allow Internet Explorer 8 Shutdown Behavior
.For参考click here
如何让window.onunload
在IE9+中工作?
希望我们的堆栈用户能帮到我。
发布于 2014-02-11 17:01:24
我不确定为什么它不能为你工作,因为我非常确定所有的IE浏览器都支持它。
尝试这种方法,总体上可能会更好:) https://developer.mozilla.org/en-US/docs/Web/Reference/Events/unload?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Funload
发布于 2014-02-11 17:11:11
我要冒险猜测一下,您的parent.logout()
方法执行了一个对服务器的异步请求。如果是这种情况,那么您的里程可能会因浏览器而异,因为大多数浏览器可能会在页面卸载时取消任何未完成的请求。
一种选择是使用同步请求,但这些请求通常不利于可用性,并且当您的服务器返回响应的时间比平时长时,会导致挫败感。
另请参阅:Can beforeunload/unload be used to send XmlHttpRequests reliably
发布于 2020-09-17 00:24:53
我也有同样的问题,不能只在IE中工作
@HostListener('window:unload', ['$event'])
unloadHandler($event) {
this.LogOut();
}
@HostListener('window:beforeunload', ['$event'])
public beforeunloadHandler($event) {
var msg = this.messageBundle['windowClosemsg']
$event.returnValue = msg;
return false
}
https://stackoverflow.com/questions/21697068
复制相似问题