-
Notifications
You must be signed in to change notification settings - Fork 40
/
popups.html
69 lines (64 loc) · 2.59 KB
/
popups.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Popup window test</title>
<style>
a {
display: block;
padding: 10px;
}
#log {
border: 1px solid black;
width: 100%;
margin-top: 50px;
min-height: 100px;
}
</style>
</head>
<body>
<h1>Popup window tests</h1>
<a href="windowfeatures.html"><a></a>
<a href="windowfeatures.html" target="_blank"><a target=_blank></a>
<a href="windowfeatures.html" wof="">window.open(...,"_blank")</a>
<a href="windowfeatures.html" wof="popup">window.open(...,"_blank","popup")</a>
<a href="windowfeatures.html" wof="popup,width=300,height=200">window.open(...,"_blank","popup,width=300,height=200")</a>
<a href="windowfeatures.html" wof="popup,left=100,top=100,width=300,height=200">window.open(...,"target=_blank","popup,left=100,top=100,width=300,height=200")</a>
<a href="https://google.com/" wof="popup">window.open("google.com","_blank","popup")</a>
<input type="checkbox" id="autoclose"><label for="autoclose">Auto-close after 5s</label><br>
<pre id="log"></pre>
<script type="text/javascript">
function log(msg) {
var l = document.querySelector("#log");
l.textContent += msg + "\n";
}
document.querySelectorAll("a[wof]").forEach(elem =>{
elem.addEventListener('click', evt => {
var w = window.open(elem.href, "_blank",elem.getAttribute("wof"));
log("Opened " + elem.href);
if (document.getElementById('autoclose').checked) {
window.setTimeout(() => {
var t;
try {
t = w.document.title;
} catch (e) {
t = e;
}
log("Closing " + elem.href + ", title=" + t);
try {
w.close();
} catch(e) {
log("Error closing: " + e);
}
}, 5000);
}
evt.preventDefault();
});
});
window.addEventListener("message", (e) => {
log("Message: " + e.data);
e.source.postMessage("Got it!","*");
}, false);
</script>
</body>
</html>