简体   繁体   English

如何使用javascript / jquery检测document.hidden中的更改?

[英]how can I detect changes in document.hidden with javascript/jquery?

I want to run some code when document.hidden is changed from false to true . document.hiddenfalse更改为true时,我想运行一些代码。

How can I do it? 我该怎么做?

You should use the visibilitychange event. 您应该使用visibilitychange事件。 See the MDN documentation for more information. 有关更多信息,请参见MDN文档

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

You should use the visibilitychange event: 您应该使用能见度更改事件:

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

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

相关问题 document.hidden时暂停/恢复setInterval - Pause/resume setInterval when document.hidden 为什么我们应该更喜欢 document.visibilityState 而不是 document.hidden? - Why are we supposed to prefer document.visibilityState to document.hidden? document.hidden 与 document.hasFocus() 之间的区别 - Difference between document.hidden vs document.hasFocus() 在WebBrowser控件中使用document.hidden错误地为false - document.hidden is incorrectly false when used in a WebBrowser control 如何检测变量何时更改JavaScript中的值? - How can I detect when a variable changes value in JavaScript? 如何通过 JavaScript/jQuery 显示隐藏的 HtmlTable“列”? - How can I show hidden HtmlTable "columns" via JavaScript/jQuery? 当 document.hidden 为 true 时,不会在 Chrome 中触发滚动事件。 任何解决方法? - Scroll event not fired in Chrome when document.hidden is true. Any workarounds? 如何使用jQuery / JavaScript检测多组单选按钮更改并更改单独的表单输入? - How do I use jQuery/JavaScript to detect multiple sets of radio button changes and change a separate form input? 我如何通过JavaScript和jQuery在word文档的标题中插入图像 - how i can insert image in header of word document by JavaScript and jQuery 如何检测缩放级别的变化? - How can I detect changes in zoom level?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM