-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresize-iframe.html
59 lines (56 loc) · 1.32 KB
/
resize-iframe.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
<!doctype html>
<head>
<meta charset="utf-8">
<title>Resize Iframe</title>
<style>
#container {
padding: 8px;
background-color: #999;
position: relative;
}
#container iframe {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
opacity: 0;
}
</style>
<script>
'use strict';
(function() {
var div = document.createElement('DIV');
var html = 'x<iframe src="javascript:false"></iframe>';
div.innerHTML = html;
var ifr = div.lastChild;
var count = 0;
window.onload = function() {
container.appendChild(ifr);
addContentBtn.onclick = addContent;
ifr.contentWindow.onresize = function() {
/**
* Skip first resize (fired after iframe "onload" event).
*/
if (count === 0) {
return;
}
onResize();
};
};
function addContent() {
var p = document.createElement('P');
p.innerHTML = 'Content ' + ++count;
container.appendChild(p);
}
function onResize() {
var p = document.createElement('P');
p.innerHTML = '[ Fire resize ' + count + ' ] ';
document.body.appendChild(p);
}
})();
</script>
</head>
<p>
<button id="addContentBtn">Add content</button>
<div id="container"></div>
</p>