如何检测“最小化"浏览器.和“最大化";在JavaScript中声明? [英] How to detect browser "minimized" and "maximized" state in JavaScript?

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

问题描述

我试图找到浏览器的 minimized maximized 状态,因为我想相应地命中AJAX请求的浏览器状态.

I am trying to find the browser minimized and maximized 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?

推荐答案

我认为检测这些状态的唯一可靠方法是检查

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天全站免登陆