有没有办法从 Javascript 检查窗口的焦点(而不是文档)?

发布于 2024-12-15 10:02:51 字数 274 浏览 0 评论 0原文

我看到了很多类似的问题,但它们都需要检查文档对象。我正在尝试从跨域 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£烟消云散 2024-12-22 10:02:51

很肯定答案是否定的。这些事情是文件的责任,而不是窗口的责任。

Pretty sure the answer is no. Such things are the responsibility of the document and not the window.

停滞 2024-12-22 10:02:51

我在另一个问题中找到了这个答案,它使用 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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文