You only need to take care of this if you are not using event monitoring, but attach your onbeforeunload
handler directly (which you do not need). If so, use something similar to avoid overwriting existing handlers.
(function() { var existingHandler = window.onbeforeunload; window.onbeforeunload = function(event) { if (existingHandler) existingHandler(event);
Unfortunately, you cannot prevent other (later) scripts from overwriting the handler. But again, this can be solved by adding an event listener instead:
$(window).unload(function(event) {
Julian D.
source share