简体   繁体   English

window.onunload 在 IE 9/10/11 中不起作用?

[英]window.onunload not working in IE 9/10/11?

The below code works fine in IE8.下面的代码在 IE8 中运行良好。

Here is my code:这是我的代码:

window.onbeforeunload = function () {

    return  "Are you sure want to LOGOUT the session ?";
}; 

window.onunload = function () {

    parent.logout();
};

But in IE9+但是在 IE9+

window.onbeforeunload works and I am getting the alert. window.onbeforeunload有效,我收到了警报。

But the window.onunload is not working.但是window.onunload不起作用。

I also tried the Group Policies in Internet Explorer 9 to enable the Allow Internet Explorer 8 Shutdown Behavior .For reference , click here我还尝试了Group Policies in Internet Explorer 9以启用Allow Internet Explorer 8 Shutdown Behavior 。有关参考, 请单击此处

How to make the window.onunload to work in IE9+ ?如何使window.onunload在 IE9+ 中工作?

Hope our stack users will help me.希望我们的堆栈用户能帮助我。

Not sure why it is not working for you, because I'm pretty sure it's supported in all those IE browsers.不知道为什么它不适合你,因为我很确定所有这些 IE 浏览器都支持它。

Try this approach, it's probably better overall :) https://developer.mozilla.org/en-US/docs/Web/Reference/Events/unload?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Funload试试这种方法,总体上可能更好:) https://developer.mozilla.org/en-US/docs/Web/Reference/Events/unload?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Funload

I'm going to hazard a guess that your parent.logout() method performs an asynchronous request to your server.我将冒险猜测您的parent.logout()方法对您的服务器执行异步请求。 If that's the case, then your mileage is likely to vary between browsers anyway, as most will probably cancel any incomplete requests when the page unloads.如果是这种情况,那么无论如何浏览器之间的里程可能会有所不同,因为大多数浏览器可能会在页面卸载时取消任何不完整的请求。

One option is to use a synchronous request, but those are generally bad for usability and cause frustration when your server takes longer than usual to return a response.一种选择是使用同步请求,但这些通常不利于可用性,并且当您的服务器需要比平时更长的时间来返回响应时会导致挫败感。

See also: Can beforeunload/unload be used to send XmlHttpRequests reliably ?另请参阅: 可以使用 beforeunload/unload 可靠地发送 XmlHttpRequests吗?

Me also same problem not working in IE only我也有同样的问题,不能只在 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
  }

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

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