阿七
级别: 未验证会员
精华:
0
发帖: 909
威望: 0 点
金钱: 2161 RMB
贡献值: 0 点
在线时间:512(小时)
注册时间:2006-03-29
最后登录:2008-08-07
|
JavaScript应用:Iframe自适应其加载的内容高度
main.htm: A@EeX4N \0m[Ch}~ey <html> +)FB[/pXk <head> ,\f
!e#d <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> [=-?n6 <meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'> `bffw:;% <title>iframe自适应加载的页面高度</title> m-UI^M,@< </head> #!KbqRt \&J7>vu^y <body> *.AokY)_a <iframe src="child.htm"></iframe> :~pPB#)nk </body> z)r)w?A </html> auqM>yx ]%3o"| child.htm: ` a5$VV%J 6';'pHqe <html> 6)kF!/J <head> S,EXc^A7 <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> [ottUS@ <meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'> eZ
y)>.6Z <title>iframe 自适应其加载的网页(多浏览器兼容)</title> Y!v `0z <script language=javascript> nM1U=Du function iframeAutoFit() <*~vZT i( {
DHJh.Y@H try `9Zoq=/ { iV[g.sP- if(window!=parent) 8'_>A5L/C { 1g5%Gr/0$5 var a = parent.document.getElementsByTagName("IFRAME"); /pZLt)=P for(var i=0; i<a.length; i++) //author:meizz :bFmw dX { :f?\ mVS+ if(a.contentWindow==window) h #Od tc1) { *r$Yv&c, var h = document.body.scrollHeight; 4:=']C if(document.all) {h += 4;} 8Br* if(window.opera) {h += 1;} YA O,
rh a.style.height = h; 3'8B rK } O E0w/{ } )uiYu3 I } t/LQ|/xo } N_lQz(nG/2 catch (ex) u;p{&\
(] { kB{ alert("脚本无法跨域操作!"); mk8xNpk B } j+"i$ln+s } NypM+y if(document.attachEvent) window.attachEvent("onload", iframeAutoFit); 2W:R{dHE else window.addEventListener('load', iframeAutoFit, false); x7)j?2 </script> bhDV U(%I6 </head> AM cHR=/ <body> \B) a57 <div style="width: 200; height: 400; background-color: yellow"> ~=9
1K
xf iframe 自适应其加载的网页(多浏览器兼容) a~E@scD </div> Dn~r~aR$g </body> '8\7(0$c </html>
|
|
[楼 主]
|
Posted: 2006-04-04 14:28 |
| |