如何在javascript中检测浏览器最小化和最大化状态 [英] How to detect browser minimize and maximize state in javascript

查看:106
本文介绍了如何在javascript中检测浏览器最小化和最大化状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到浏览器最小化和最大化状态,因为我想相应地点击AJAX请求浏览器状态。

I am trying to find the browser minimize and maximize states, as I want to hit the AJAX request accordingly the browser state.

有谁知道如何检测使用JavaScript的浏览器状态。

Does anyone know how do I detect the browser state using JavaScript.

推荐答案

我认为检测这些状态的唯一可靠方法是检查可见性API (这仍是一项实验性功能),提供某些属性和事件

I think the only reliable way to detect these states is to check the visibility API offered by HTML5 (this is still an experimental feature) which offers certain properties and events

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    

您还可以对可见性的变化做出反应

You can also react on changes of the visibility

document.addEventListener("visibilitychange", function() {
  console.log(document.hidden, document.visibilityState);
}, false);

请记住,这不适用于跨浏览器,仅适用于某些浏览器版本。

Keep in mind this is not working cross browser and only available in certain browser versions.

这篇关于如何在javascript中检测浏览器最小化和最大化状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆