I have been using this, although I did not realize it was functioning improperly in ie8 until recently.
$(window).blur(function () {
alert("lost");
});
In firefox or chrome or safari, this properly results in an alert being shown when the window loses focus. However, in IE8 it seems that the alert is put into some sort of queue. The alert “lost” only shows when the window regains focus. What is more confusing is that when coupled with an event which tracks if the window gains focus, they go out of order.
$(window).focus(function () {
alert("gained");
});
(don’t try this in chrome or firefox because the alerts will enter some sort of cycle)
If both of those are used with IE8, when the window loses focus, and then regains it, IE8 alerts “gained” ok “lost”. This out of order event firing causes my code issues because it is backwards, and reports that the last event was the browser losing focus.
How can I track this in IE8?
credit for approach: https://stackoverflow.com/a/10999831/1026459
Solution for my situation:
This actually controls an interval, but that is besides the point.
onfocusoutworks for ie8,chrome, safari, and ff. I am not sure what issue ie8 had withblurbut I am phasing it out.EDIT
Unfortunately document.onfocusout did not work in chrome or safari so I had to do more workaround. Here is what I ended up with.