PDA

View Full Version : window.onbeforeunload


mankz
03-26-2009, 08:44 AM
I'm having some trouble grasping how onbeforeunload works (I'm using FF3). I want to prompt the user if unsaved changes exist when they try to leave my page. My handlers are called correctly in both scenarios below, I've tested with an alert which is shown as expected.

This version works, I get a confirm popup, but using this will wipe out any previously registered handlers. Maybe Ext will do some cleaning on beforeunload (right now it looks like Ext cleans up on unload event) and I don't want to overwrite previously registered handlers.
window.onbeforeunload = this.onBeforeUnload.createDelegate(this);

This version does not work, nothing happens when I leave the page
Ext.EventManager.on(window, 'beforeunload', this.onBeforeUnload, this);

The event handler
onBeforeUnload : function(evt) {
return "message";
}

Does anyone know why this doesn't work?

hendricd
03-26-2009, 09:39 AM
Ext.EventManager.on(window, 'onbeforeunload', this.onBeforeUnload, this);

mankz
03-26-2009, 09:42 AM
That was just a typo in the forum post sorry, I use the code you wrote. Still doesn't work.