View Full Version : unload Event

17 Aug 2009, 3:26 PM
I can't seem to get this to fire:

Ext.EventManager.on(window, 'unload', function(evt) {

Is there some magical place this needs to go? I've tired it on the bottom of the Ext.onReady function and in the on('load') of the last of my data stores.

18 Aug 2009, 3:21 AM
Your 'window' is Ext.Window or the native browser window?

18 Aug 2009, 6:06 AM
The native window browser. I'm trying to get something to fire when I close a tab, exit firefox, go to another tab, etc. That is, whenever my current page is no longer visible.

18 Aug 2009, 6:10 AM
Switching tabs won't fire an unload event.

The unload event is only fired when you navigate to a different url.

18 Aug 2009, 6:16 AM
For switching tabs and also switching to different applications on the OS level:

window.onblur = function() {
old_title = document.title;
document.title = '(Inactive) '+ document.title;

window.onfocus = function() {
document.title = old_title;
}Tested on Firefox 3.5 and IE8

now i'm sure you can imagine how to handle the unload event .. ;)

18 Aug 2009, 6:55 AM
Will the onblur fire when you exit Firefox? Here's my issue: I enable cut and paste for my page the first time someone selects a string. If the user allows, this capability is stored in prefs.js for Firefox. When Firefox tries to load my page after a restart, my web server logs:

INFO: dwr-invoker: A request has has been denied as a potential CSRF attack.

What I thought I'd do is disable cut and paste when I exit Firefox (or change to another app) and, it is my hope, that will remove the capability from prefs.js.