有没有办法从 Javascript 检查窗口的焦点(而不是文档)?
我看到了很多类似的问题,但它们都需要检查文档对象。我正在尝试从跨域 iframe 执行此操作,因此我无法访问 top.document。有什么办法可以处理 window.top 对象吗?
更新:请参阅我的回答如下
I see numerous questions along these lines, but they all require checking the document object. I'm trying to do this from a cross-domain iframe, so I don't have access to top.document. Any way to do with with the window.top object?
UPDATE: see my answer below
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很肯定答案是否定的。这些事情是文件的责任,而不是窗口的责任。
Pretty sure the answer is no. Such things are the responsibility of the document and not the window.
我在另一个问题中找到了这个答案,它使用 window.onfocus 和window.onblur。不幸的是,浏览器安全性似乎阻止将事件附加到 window.top.onfocus/blur...
I found this answer in another question, which uses window.onfocus and window.onblur. Unfortunately browser security seems to prevent attaching events to window.top.onfocus/blur....