简体   繁体   English

如何使用Javascript检测当前窗口是否在另一个窗口后面

[英]How to detect if current window is behind another window, using Javascript

Is it possible to detect whether the web browser window is currently covered by another window?是否可以检测 Web 浏览器窗口当前是否被另一个窗口覆盖?

document.hidden and document.visibilityState only changes state on switching tabs or when the entire window is minimized. document.hidden 和 document.visibilityState 仅在切换选项卡或最小化整个窗口时更改状态。

document.hasFocus() returns false if the window is visible but not in focus (eg the focus is on the taskbar)如果窗口可见但不在焦点上(例如焦点在任务栏上),则 document.hasFocus() 返回 false

Nope, that's not possible.不,那是不可能的。

There's no way in JavaScript to know how visible the window is. JavaScript 无法知道窗口的可见性。

Browser windows overlapping one another, the position of the browser windows, and which one of them is on top - these functionalities are handled by the operating system.浏览器窗口相互重叠、浏览器窗口的位置以及其中一个位于顶部 - 这些功能由操作系统处理。

No matter what code you write for your webpage, you cannot tell if your browser window is overlapped by another.无论您为网页编写什么代码,都无法判断您的浏览器窗口是否与另一个窗口重叠。

So yeah, the answer is NO .所以是的,答案是否定的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM