views:

1761

answers:

1

Hello,

$(window).blur(function(){
 windowFocus = false;
}).focus(function(){
 windowFocus = true;
});

The problem is that in firefox 3, when I create a new tab, it does not lose windowFocus. Where as in ff2, ie7 it does lose. In ff3 it only loses window focus when i select another program.

Anyone have a solution to this problem?

+1  A: 

Attach to the events on document instead:

$(document).blur(function(){
        windowFocus = false;
}).focus(function(){
        windowFocus = true;
});

...FWIW, this appears to have been fixed in FF3.5.

Shog9
will this work for ie6/7/8 and ff2? or do i need to write it as a hack?
Alec Smart
No, but you can probably get away with just wiring up both (since the document can't have focus without the window having focus): $(window, document)...
Shog9
@Shog9: that will search for the window object in the document object, the comma only works in string selectors for specifying multiple selectors. Try this instead: $(window).add(document)...
Pim Jager
@Pim Jager: ah, of course... I've made that mistake a few times, sad to say! $([window, document]) should also work.
Shog9