单击插件时保留浏览器窗口焦点
我有一个网页,它使用 javascript 计数器来计算用户“活动”时间,这意味着用户花在查看此页面(而不是其他页面)上的时间。我通过使用 document.onfocusout/onfocusin (IE)和 window.onblur/onfocus (其他)启动/停止它们来做到这一点 但是,当用户单击同一页面内的插件(flash、java 等)时,窗口将失去焦点并触发 window.onblur。有没有办法判断用户仍在我的页面上?
提前致谢
I have a web page that uses javascript counters to count user "active" time, meaning the time a user spends viewing this page (and not some other page). I do this by starting/stopping them using the document.onfocusout/onfocusin (IE) and window.onblur/onfocus (other)
However, when the user clicks on a plugin inside the same page (flash, java, etc), the window loses focus and window.onblur is fired. Is there a way to tell that the user is still on my page?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这确实是一个问题。但你可以用诡计摆脱它。 Flash Player 能够与其脚本主机(在本例中为 JavaScript 主机)进行通信。您要做的是,当 Flash Player 影片接收到焦点时(我相信您可以使用 ActionScript 捕获焦点),您可以对其进行编程,以使用
ExternalInterface
Flash Player 类 API 通知其主机,该 API 会调用JavaScript 函数,它将再次启动计时器(并且可以选择将焦点返回到页面,因为从页面窃取焦点通常是一个坏主意。默认情况下,Flash Player 会窃取焦点 - 如果您单击Flash Player 电影、键盘不被 JavaScript 捕获更长,仅直接通过 Flash Player。)你明白我在说什么吗?
It is a problem indeed. But you can trick your way out of it. Flash Player is able to communicate with its scripting host, in your case the JavaScript host. What you do is that when Flash Player movie receives focus, which I believe you are able to catch with ActionScript, you program it to notify it's host using the
ExternalInterface
Flash Player class API, which will say, call a JavaScript function, which will start the timer again (and optionally give focus back to the page because most often stealing focus from the page is a bad idea. Flash Player steals focus by default - if you click a Flash Player movie, keyboard is not caught by JavaScript any longer, only straight by Flash Player.)Do you understand what I'm saying?