当前位置:网站首页>Browser window switch activation event visibilitychange
Browser window switch activation event visibilitychange
2022-06-30 19:17:00 【AdleyTales】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<h1> Browser window switch activation event </h1>
<div id="app"></div>
<script>
/**
* visibilitychange: When browser visibility changes , This event will be triggered
*
* We can do it in document Object visibilitychange event ,
* according to document.hidden perhaps document.visibilityState Attributes do some business logic .
*
* Example scenario
* Client embedded H5 A scenario often encountered on a page :H5 Page has a video , While it's playing , Click other buttons on the page ,
* Enter the client native page , Or open a new webview, The video should be paused , When returning to this page , The video continues to play .
*
*/
document.addEventListener('visibilitychange', (ev) => {
// console.log(ev);
console.log(document.hidden, document.visibilityState) // visible hidden
console.log('----active window ------')
if(!document.hidden) {
doSomething()
}
}, false)
function doSomething() {
console.log('do some thing ...')
}
</script>
</body>
</html>
effect

边栏推荐
- 20220607跌破建议零售价,GPU市场正全面走向供过于求...
- MySQL 索引测试
- 《被讨厌的勇气:“自我启发之父”阿德勒的哲学课》
- Teach you to quickly set up a live studio in 30 minutes
- Development: how to install offline MySQL in Linux system?
- Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
- 联想YOGA 27 2022,超强配置全面升级
- Reading notes of "high EQ means being able to talk"
- 拓维信息使用 Rainbond 的云原生落地实践
- 一点比较有意思的模块
猜你喜欢
随机推荐
ArcGIS无插件加载(无偏移)天地图
挖财账号开户安全吗?是靠谱的吗?
法国A+ 法国VOC标签最高环保级别
DTD modeling
Go redis connection pool
3.10 haas506 2.0开发教程-example-TFT
Dlib库实现人脸关键点检测(Opencv实现)
Leader: who can use redis expired monitoring to close orders and get out of here!
How does rust implement dependency injection?
com.alibaba.fastjson.JSONObject # toJSONString 消除循环引用
3.10 haas506 2.0 development tutorial example TFT
Kubernetes----Pod配置容器启动命令
基于UDP协议设计的大文件传输软件
torch stack() meshgrid()
Kalman滤波器--从高斯融合推导
Year after year, why is breaking the data island still the primary task of enterprise development
VS 常用的快捷键指令
[community star selection] the 23rd issue of the July revision plan | bit by bit creation, converging into a tower! Huawei freebuses 4E and other cool gifts
教你30分钟快速搭建直播间
mysql函数获取全路径









