开发者

window.onFocus intermittently doesn't fire on Chrome

I'm trying to determine whether or not a tab is focused, for a chatroom app. I have:

window.onfocus = function () {
  isActive = true;
};
window.onblur = function () {
  isActive = false;
};

This works perfectly in Firefox and even in IE. But in Chrome, it only works intermittently; sometimes the event will fire, sometimes not. It will always fire if 开发者_Go百科I click on a different window then click back to the Chrome window; but switching tabs doesn't always do it.

What can I do about this?

See live example here: http://holyworlds.org/new_hw/chat/onfocus.html


This appears to be a bug in Chrome\Windows, since Chrome on other platforms is unaffected.

Bug filed here: http://code.google.com/p/chromium/issues/detail?id=87812


You forgot the rest of the script.

Try this

var isActive = true;
window.onfocus = function () {
  isActive = true;
    document.title = window.isActive;
};
window.onblur = function () {
  isActive = false;
    document.title = window.isActive;
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜