简体   繁体   English

检测“浏览器”选项卡是否专注于移动浏览器

[英]Detect If Browser Tab is focused on mobile browsers

I am willing to detect if the tab is in focus on as many mobile browsers as possible. 我愿意检测选项卡是否集中在尽可能多的移动浏览器上。

I saw that the common use in determining visibility is "document.hidden" or "document.visibilityState" , but on https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden#Browser_compatibility is listed that it's not compatible on IE mobile . 我看到确定可见性的常用方法是“ document.hidden”“ document.visibilityState” ,但是在https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden#Browser_compatibility是列出它与IE mobile不兼容

Found also that many use document.addEventListener("visibilitychange", function() {}) - which also seems to might not be compatible on IE Mobile. 还发现许多人使用document.addEventListener(“ visibilitychange”,function(){}) -似乎在IE Mobile上也不兼容。

Another less common use is document.hasFocus() which is not supported in Opera Mini and might not be supported in Safari and Mobile Chrome.. 另一个较不常用的用法是document.hasFocus() ,Opera Mini不支持,而Safari和Mobile Chrome可能不支持。

plus, the "window.onblur" doesn't seem to work on chrome emulator. 另外,“ window.onblur”似乎无法在Chrome仿真器上运行。

Anyone knows maybe another way to check if the browser is in focus on all mobile browsers? 有谁知道另一种检查浏览器是否集中在所有移动浏览器上的方法? or maybe one of the above is actually compatible to all? 也许上述之一实际上与所有人兼容?

Have you tried using the two events: 您是否尝试过使用以下两个事件:

window.onfocus and window.onblur ? window.onfocuswindow.onblur吗?

You can associate code which triggers when it focuses and it blurs, so actually you can detect when it's not focused 您可以关联在聚焦时触发并模糊的代码,因此实际上您可以检测到何时未聚焦

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

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