-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgvisibility.html
70 lines (59 loc) · 2.49 KB
/
pgvisibility.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- basic.html -->
<title>Page visibility API</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Page visibility API</h1>
<p></p>
<!--
!!!!!
!!!!!
WICHTIG - DAS ENABLEJSAPI=1 BEACHTEN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!
!!!!!
-->
<!--<iframe width="420" height="315" src="https://www.youtube.com/embed/tgbNymZ7vqY?enablejsapi=1"> </iframe>-->
<iframe src="https://www.youtube.com/embed/DLzxrzFCyOs?enablejsapi=1" width="420" height="315" frameborder="0" allowfullscreen=""></iframe>
<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.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
var iframe = document.getElementsByTagName("iframe")[0].contentWindow;
// If the page is hidden, pause the video;
// if the page is shown, play the video
function handleVisibilityChange() {
if (document[hidden]) {
console.log("hidden");
document.title = 'Paused';
iframe.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
} else {
console.log("visible");
document.title = 'Playing';
iframe.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
}
}
// Warn if the browser doesn't support addEventListener or the Page Visibility API
if (typeof document.addEventListener === "undefined" || hidden === undefined) {
console.log(
"This demo requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API."
);
} else {
// Handle page visibility change
document.addEventListener(visibilityChange, handleVisibilityChange, false);
}
</script>
<a href="index.html"> back </a>
</body>