PDA

View Full Version : Help managing onbeforeunload or onunload events browser



jaadolio
21 Feb 2011, 11:54 AM
Good Afternoon:

I need some assistance regarding the use of standard onbeforeunload or onunload events.

I have created an application that uses PHP sessions for users to login in which it includes a "logout" option to exit the website (destroying the session).

However I need to be able to control when user clicks the browser's Close Button (X), so that I can activate a MessageBox confirmation advising the user correctly.

I tried using Ext.EventManager registering the "beforeunload" event. It helps me control the closing action, but it displays the default confirm message from the browser:

"Are you sure you want to navigate away from this page?... Press OK to continue, or Cancel to stay on the current page."

According to some forums, this message is not able to be changed programmatically, but probably if I let this being managed like this, my users will get confused...

Another thing is that "beforeunload" is not being activated in other browsers like Opera (vers. 11.01)

Is there some special feature or event in ExtJS that can help me out with this like the one included on the Dojo Toolkit framework [dojo.addonUnload]?

Thanks...

jaadolio
21 Feb 2011, 12:43 PM
Any suggestion or recommendation will be appreciated!!!

Dipish
1 Nov 2011, 8:21 AM
Unfortunately, the implementation of onbeforeunload situation is totally up to the browser. I bumped into this too... So far, no news AFAIK.

darthwes
1 Nov 2011, 9:29 AM
The onbeforeunload event, as you've described, doesn't seem to be fired by all the browsers, anyway. On some, however, the event does fire, it's just synchronous, so you can't initiate an ajax request.

What seems to work for me is to perform a synchronous XHR request, which, again, sucks, but IDK what else to do. That seems to catch the bulk of user logouts for me, but I don't have a lot of users on Opera, either.