blob: d6f93d87a0b5a93313deafc5603b0166642f42fb (
plain)
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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hasFocus() outer</title>
<script>
var w = null;
var hadInitialFocus = false;
var hadLostFocus = false;
window.onmessage = function(e) {
if (e.data == "restored") {
if (hadInitialFocus && hadLostFocus) {
let verdict = document.hasFocus() ? "PASS" : "FAIL: hasFocus false";
window.opener.postMessage(verdict, "*");
} else {
window.opener.postMessage("FAIL: should have failed already", "*");
}
} else if (e.data == "focused") {
w = window.open("hasfocus-other.html");
} else if (e.data == "noblur") {
window.opener.postMessage("FAIL: no inner blur", "*");
} else if (e.data == "opened") {
if (document.hasFocus()) {
w.close();
window.opener.postMessage("FAIL: focus not lost when other window opened", "*");
} else {
hadLostFocus = true;
window.frames[0].postMessage("hasfocus", "*");
}
} else if (e.data == "close") {
w.close();
} else if (e.data == "wrongfocus") {
w.close();
window.opener.postMessage("FAIL: hasFocus was true in iframe", "*");
}
}
window.onload = function() {
if (document.hasFocus()) {
hadInitialFocus = true;
window.frames[0].postMessage("focus", "*");
} else {
window.opener.postMessage("FAIL: did not have initial focus", "*");
}
}
</script>
</head>
<body>
<iframe src="hasfocus-inner.html"></iframe>
</body>
</html>
|