Code:
function addListener(obj, evt, handler)
{
if (obj.addEventListener)
{
obj.addEventListener(evt, handler, false);
}
else if (obj.attachEvent)
{
obj.attachEvent('on' + evt, handler);
}
}
addListener(window, 'beforeunload', a_function);
Handlers assigned using these methods do not overwrite previous assignments, but simply add new ones. There are functions that specifically check the property involved (window.onbeforeunload, e.g.) and 'bundle' the old handler with the new; however, the above method is well-supported and works. Hopefully you can include it in that application.
Other route:
Code:
function addbeforeunloadEvent(func)
{
var oldonbeforeunload = window.onbeforeunload;
if (typeof window.onbeforeunload != 'function') {
window.onbeforeunload = func;
} else {
window.onbeforeunload = function() {
oldonbeforeunload();
func();
}
}
}