demonstration of how the priority of beforeunload and unload events works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ifr = document.createElement('iframe'); | |
document.body.appendChild(ifr); | |
// top window's beforeunload event would be the first one to fire | |
window.onbeforeunload = function(e) { | |
console.log('first event to fire (1)'); | |
}; | |
// other windows beforeunload events would fire after top window | |
ifr.contentWindow.onbeforeunload = function(e) { | |
console.log('second event to fire (2)'); | |
}; | |
// top window's unload event would fire after all beforeunload events have been fired | |
window.onunload = function(e) { | |
console.log('third event to fire (3)'); | |
}; | |
// other windows unload events would fire after top window | |
ifr.contentWindow.onunload = function(e) { | |
console.log('fourth event to fire (4)'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment