我正在尝试查找浏览器最小化和最大化状态,因为我想根据浏览器状态触发AJAX请求。
有谁知道如何使用 JavaScript 检测浏览器状态?
最佳答案
我认为检测这些状态的唯一可靠方法是检查 visibility API由 HTML5 提供(这仍然是一个实验性功能),它提供某些属性和事件
document.hidden // Returns true if the page is in a state considered to be hidden to the user, and false otherwise.
document.visibilityState // Returns a string denoting the visibility state of the document
您还可以对可见性的变化使用react
document.addEventListener("visibilitychange", function() {
console.log(document.hidden, document.visibilityState);
}, false);
请记住,这不适用于跨浏览器,并且仅在某些浏览器版本中可用。
关于javascript - 如何在JavaScript中检测浏览器 "minimized"和 "maximized"状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41490293/