Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors.
So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not understand, that return value NULL is supposed to mean ‘Do not show the confirm’.
var origOnBeforeUnload = window.onbeforeunload; window.onbeforeunload = function(event) { if(typeof origOnBeforeUnload === 'function') { return origOnBeforeUnload(event); } }
We needed to implement little more robust checking, and when we do not want to show a message, you need to not return anything.
var origOnBeforeUnload = window.onbeforeunload; window.onbeforeunload = function(event) { //do any code you want to if(typeof origOnBeforeUnload === 'function') { var out = origOnBeforeUnload(event); if(typeof out !== 'undefined' && out !== null && out !== false) return out; } } }