【问题标题】:Is there a way of checking the window's focus (not the document) from Javascript?有没有办法从 Javascript 检查窗口的焦点(而不是文档)?
【发布时间】:2011-12-29 18:17:00
【问题描述】:

我看到许多类似的问题,但它们都需要检查文档对象。我正在尝试从跨域 iframe 执行此操作,因此我无权访问 top.document。与 window.top 对象有什么关系?

更新:见下面的my answer

【问题讨论】:

    标签: javascript iframe focus cross-domain


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我找到了this answer in another question,它使用了window.onfocus 和window.onblur。不幸的是,浏览器安全似乎阻止将事件附加到 window.top.onfocus/blur....

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多