I want to be able to tell when a window that I open is closed by the user. This is the code of my attempt at monitoring this:
&l
The window first loads with a blank page and then unloads the page, causing the unload
event.
Your page then loads. Try attaching the event when the onload
event fires to avoid this.
Simple demo
document.getElementById('openWindow').onclick = function () {
var windowref = window.open('tests2.html');
windowref.onload = function() {
windowref.onunload = function () {
window.alert('hola!');
};
}
};