Reputation: 299
I am opening a window through window.open
method. This window is for conducting test. Can i know how to detect the event when user closes the popup window. I want to detect this in popup window only not parent window.I mean kind of ajax request to insert a value in database when user closes it. I have tried onbeforeunload
but it does not works. Please help me
Upvotes: 2
Views: 2975
Reputation: 2898
Pretty simple try this
$(window).on('beforeunload', function() {
return 'Are you sure want to logout ?';
});
$(window).unload(function() {
debugger; // when closing window debugger will hit here
});
Upvotes: 1
Reputation: 3317
If you want to know when a window or tab is closed then use unload
or onbeforeunload
, these events are fired too, when you leave the site by a link.
The API for jQuery unload()
:
https://api.jquery.com/unload/
...and pure javascript: https://developer.mozilla.org/de/docs/Web/API/WindowEventHandlers/onbeforeunload
Upvotes: 0