-
Notifications
You must be signed in to change notification settings - Fork 108
/
dynamic-insert.html
58 lines (47 loc) · 1.67 KB
/
dynamic-insert.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
<!doctype html>
<html lang="en" class="js ">
<head>
<meta charset="utf-8">
<!--[if IE]><![endif]-->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Iframe - dynamic insertion, after onload</title>
<meta name="description" content="">
</head>
<body>
<h1>Iframe - dynamic insertion, after onload</h1>
<ul>
<li>Iframe is created dynamically (appendChild) with JS
<li>Creation of iframe happens after onload
<li>Onload of main page fires soon, since the page only has 1 image
<li>Onload of the iframe fires after ~2.5 seconds (all iframe content done loading)
<li>While the iframe is loading, one or more browser busy indicators show something is loading
</ul>
<div id="test1">
</div>
<p>
<img src="http://www.aaronpeters.nl/sandbox/images/calendar.png" width="128" height="128" alt=""><br>
</p>
<script>
//doesn't block the load event
function createIframe(){
console.log('onload已经触发了');
var i = document.createElement("iframe");
var a = Math.random() + "";
var t = a * 10000000000000;
i.src = "http://1.cuzillion.com/bin/resource.cgi?type=gif&sleep=2&n=1&t=" + t;
i.scrolling = "auto";
i.frameborder = "0";
i.width = "200px";
i.height = "100px";
document.getElementById("test1").appendChild(i);
};
// Check for browser support of event handling capability
if (window.addEventListener)
window.addEventListener("load", createIframe, false);
else if (window.attachEvent)
window.attachEvent("onload", createIframe);
else window.onload = createIframe;
</script>
</body>
</html>
<!-- http://www.webpagetest.org/result/101215_3a0cd9a522be1fee6ea7fb5006122f67/ -->