window.onblur – strange behavior on browsers
About a year ago I posted an example for using externalInterface to start and stop sound inside flash, based on focus and blur events in the window. After recently receiving several comments and questions about strange behavior on different browsers, I decided to test the script on the browsers I have on my Mac and PC.
Originally I was using the onFocus & onBlur events, attached to the window object, I found out that each browser can deal with these event when attached to a different object, I started testing which object works for each browser, and added browser sniffer for the listener definition, these are the objects for each browser:
Browser
Object
Safari, Opera, Omniweb
window
Firefox
window.document
IE7
document.body (* partially working)
And here are the results:
Mac OS X 10.5.2 Leopard
Safari
All working fine.
Firefox
onblur is only fired when loosing focus to another Firefox window, not to another app.
Opera
All working fine.
Omniweb
All working fine.
Windows XP
IE7
Firefox
onfocus is fired twice when clicked on body, once when clicked on browser title.
The situation on Mac seems to be much better than on Windows XP (sorry, I did not test Vista, so if someone can try this on Vista and send me the results – it would be great), currently both IE7 and Firefox on XP have strange behavior.
With IE7 it gets even weirder, when IE7 has Tabbing enabled, it can’t handle onblur event for body object, while without tabbing, onblur works if clicked on the browser title area, once clicked inside the window (Html body) “something” goes crazy and both onfocus and onblur are fired together upon focus event.
Here is the test page, you will find the events I tested for IE7 commented in the page source.
Does anyone know a way around this strange behavior on IE7 and Firefox?
any way to make this listener compatible with all browsers?
