<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>切屏检测</h1>
</body>
<script>
// 检测页面是否被隐藏
document.addEventListener('visibilitychange', function () {
if (document.hidden) {
// 用户切换到其他标签页或最小化窗口
console.log("用户切换到其他标签页或最小化窗口");
alert("警告!!!用户切换到其他标签页或最小化窗口")
} else {
// 用户回到当前标签页
console.log("用户回到当前标签页");
}
});
// 检测鼠标是否离开浏览器窗口
document.addEventListener("mouseleave", function () {
console.log("鼠标离开浏览器窗口");
alert("警告!!!鼠标离开浏览器窗口")
});
</script>
</html>
浏览器切屏检测
于 2023-08-11 09:08:52 首次发布