admin管理员组文章数量:1427321
My page should make notification sounds only when the window is in the background. I can track the window.onfocus
and window.onblur
events to notice when the focus state changes. However, I don't know whether the window will load focused or not, since it might load in a background tab, for instance.
How do I decide whether to play sounds or not before I get an onfocus
/onblur
event?
My page should make notification sounds only when the window is in the background. I can track the window.onfocus
and window.onblur
events to notice when the focus state changes. However, I don't know whether the window will load focused or not, since it might load in a background tab, for instance.
How do I decide whether to play sounds or not before I get an onfocus
/onblur
event?
2 Answers
Reset to default 2Couldn't you just assume it's loaded blurred, and then change the status to focused as soon as you receive any type of event (keydown/mousemove)?
The onfocus event should be triggered when the page is initially opened (in the foreground). At least it is in FF3/IE8.
So you could have sounds on initially, turn them off when onfocus is triggered, and turn them back on when onblur is triggered.
本文标签: javascriptHow can I detect whether a browser window is focused or notStack Overflow
版权声明:本文标题:javascript - How can I detect whether a browser window is focused or not? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745492394a2660658.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论