-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPageVisibilityAPIExample01.htm
executable file
·38 lines (31 loc) · 1.48 KB
/
PageVisibilityAPIExample01.htm
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
37
38
<!DOCTYPE html>
<html>
<head>
<title>Page Visibility Example</title>
<script src="EventUtil.js"></script>
</head>
<body>
<p>This page is a demonstration of the Page Visibility API. This is known to work in Internet Explorer 10+ and Chrome.</p>
<p>Try minimizing the window, or switching to another tab. The page will update with the various states.</p>
<script>
function isHiddenSupported(){
return typeof (document.hidden || document.msHidden || document.webkitHidden) != "undefined";
}
function handleVisibilityChange(){
var output = document.getElementById("output"),
msg;
if (document.hidden || document.msHidden || document.webkitHidden){
msg = "Page is now hidden." + (new Date()) + "<br>";
} else {
msg = "Page is now visible." + (new Date()) + "<br>";
}
output.innerHTML += msg;
}
//need to add to both
EventUtil.addHandler(document, "msvisibilitychange", handleVisibilityChange);
EventUtil.addHandler(document, "webkitvisibilitychange", handleVisibilityChange);
</script>
<p><script>document.write(isHiddenSupported() ? "Your browser supports the Page Visibility API." : "Your browser does not support the Page Visibility API.");</script></p>
<div id="output"></div>
</body>
</html>