有没有一种从Javascript检查窗口焦点(不是文档)的方法?

Is there a way of checking the window's focus (not the document) from Javascript?

本文关键字:文档 方法 焦点 检查 一种 有没有 Javascript 窗口      更新时间:2023-09-26

我看到过许多类似的问题,但它们都需要检查文档对象。我正试图从跨域iframe做到这一点,所以我没有访问top.document。跟窗户有什么关系都行。前对象?

更新:见下面我的回答

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

我在另一个使用window的问题中找到了这个答案。Onfocus和window。onblur。不幸的是,浏览器安全似乎阻止将事件附加到window.top.onfocus/blur....