我正在尝试寻找浏览器最小化 and 最大化状态,因为我想根据浏览器状态触发 AJAX 请求。
有谁知道如何使用 JavaScript 检测浏览器状态?
我认为检测这些状态的唯一可靠方法是检查可见性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
您还可以对可见性的变化做出反应
document.addEventListener("visibilitychange", function() {
console.log(document.hidden, document.visibilityState);
}, false);
请记住,这不适用于跨浏览器,并且仅在某些浏览器版本中可用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)