Help managing onbeforeunload or onunload events browser
Help managing onbeforeunload or onunload events browser
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]?
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.