View Single Post
Old 05-07-2009, 07:06 PM   PM User | #2
adios
Senior Coder

 
Join Date: Jun 2002
Posts: 1,403
Thanks: 2
Thanked 31 Times in 31 Posts
adios is on a distinguished road
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();
        }
    }
}

Last edited by adios; 05-07-2009 at 09:44 PM..
adios is offline   Reply With Quote