onunload
is responsible for executing an instruction when the page is closed. It also causes issue with IE and AJAX.
onbeforeunload
is more efficient because it does not run in competition with the actual closing of the window and is triggered before onunload
I know Opera used to not acknowledge onbeforeunload
- not sure if they've fixed that, but I always register the listener for both to be safe:
window.onunload = window.onbeforeunload = (function(){...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…