-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiframe自适应高度
101 lines (47 loc) · 1.51 KB
/
iframe自适应高度
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
原创:兼容 IE Firefox Opera chrome的iframe自适应高度
test.html如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>test iframe</title>
<script type="text/javascript">
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
if (Sys.opera || Sys.safari)
{
window.setInterval("reinitIframe()", 200);
}
function reinitIframe() //针对opera safari
{
var iframe = document.getElementById("PandL");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
function iframeAutoFit(iframeObj)
{
setTimeout(function()
{
if(!iframeObj)
return;
iframeObj.height=(iframeObj.Document?iframeObj.Document.body.scrollHeight:iframeObj.contentDocument.body.offsetHeight);
},200)
}
</script>
</head>
<body>
<div align="center" id="bodyL">
<iframe src="lzxhll.html" scrolling="no" width="80%" height="300"
name="PandL" id="PandL" onLoad="javascript:iframeAutoFit(this);"></iframe>
</div>
</body>
</html>