-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsize-cross-origin-child.js
54 lines (40 loc) · 1.36 KB
/
size-cross-origin-child.js
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
;(function(document, window, undefined) {
'use strict';
if (!document.addEventListener) {
return;
}
function init() {
var owner = null,
width = Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth),
height = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight),
iframe = RegExp('[?&]iframe=([a-z\-]+)').exec('?iframe=iframe'); // window.location.search
if (iframe) {
try {
owner = parent.document; // Same domain access?
} catch (e) {
}
if (owner) {
var iframe = owner.getElementById(decodeURIComponent(iframe[1]));
if (iframe) {
iframe.style.height = height + 'px';
return;
}
}
}
if (parent.postMessage) {
owner = parent;
} else if (parent.contentWindow && parent.contentWindow.postMessage) {
owner = parent.contentWindow;
} else {
owner = null;
}
if (owner) {
owner.postMessage({'request' : 'iframeReize', 'width' : width, 'height' : height}, '*');
}
}
if (document.readyState !== 'loading') {
window.setTimeout(init); // Handle asynchronously
} else {
document.addEventListener('DOMContentLoaded', init);
}
})(document, window);