forked from bluemarvin/html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visibility.html
36 lines (34 loc) · 1.13 KB
/
visibility.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!doctype html>
<html>
<head>
<title>visibility</title>
<script>
// Set the name of the hidden property and the change event for visibility
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
function handleVisibilityChange() {
if (document[hidden]) {
console.log("hidden");
} else {
console.log("visible");
}
}
document.addEventListener(visibilityChange, handleVisibilityChange, false);
</script>
</head>
<body>
<h1>Visibility Event Test</h1>
</body>
</html>