PDA

View Full Version : window beforeunload event



Lobo
22 Jul 2010, 10:42 AM
The following works OK in my 3 browsers (FF / IE / Chrome):



window.onbeforeunload = function() {
return 'sure?'
}


BUT the following (supposedly equivalent) Ext specific way does NOT work as expected in Chrome:



Ext.EventManager.on(window, 'beforeunload', function(e){
alert('beforeunload')
e.browserEvent.returnValue = 'sure?'
})


In Chrome, the alert gets executed (i.e. it properly fires the event), but it does NOT prompt the user with the "sure?" confirmation message, in fact no message at all.

Shouldn't both of the above code snippets behave the same?.

Why does it work different in Chrome?.

Thanks in advance.

Lobo

Animal
22 Jul 2010, 10:51 AM
Because there's no standard covering it. So you're onto a loser there.

http://www.w3.org/TR/DOM-Level-2-Events/events.html