Reputation: 8387
The below code works fine in 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+
window.onbeforeunload
works and I am getting the alert.
But the window.onunload
is not working.
I also tried the Group Policies in Internet Explorer 9
to enable the Allow Internet Explorer 8 Shutdown Behavior
.For reference , click here
How to make the window.onunload
to work in IE9+ ?
Hope our stack users will help me.
Upvotes: 1
Views: 9720
Reputation: 13
Me also same problem not working in IE only
@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
}
Upvotes: -1
Reputation: 344713
I'm going to hazard a guess that your parent.logout()
method performs an asynchronous request to your server. 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?
Upvotes: 0
Reputation: 93
Not sure why it is not working for you, because I'm pretty sure it's supported in all those IE browsers.
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
Upvotes: 0