阿七
级别: 未验证会员
精华:
0
发帖: 909
威望: 0 点
金钱: 2161 RMB
贡献值: 0 点
在线时间:512(小时)
注册时间:2006-03-29
最后登录:2008-08-07
|
JavaScript应用:Iframe自适应其加载的内容高度
main.htm: !ldEy#"X vT#R>0@mi <html> qVh?%c1.Y <head> gba1R <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> l0G{{R0Y <meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'> P.>fkO1\ <title>iframe自适应加载的页面高度</title> FZgf"XM
> </head> X}'rPz\Lu x9F*$G <body> ~EmK
;[Z <iframe src="child.htm"></iframe> N$>Ml!J </body> RK@K>)"f </html> gA=Pz[i)p N=u(
3So child.htm: 7J3A]>qU _L)LyQD]T <html> <!t;[ie?y <head> fUvXb>f, <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> JQ
?8yl
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'> jA^yUd- <title>iframe 自适应其加载的网页(多浏览器兼容)</title> ,8DC9yM, <script language=javascript> <>KQ8:
function iframeAutoFit() T=w0T-[f { I[A<e]uK try >Ch2
Ep { dgQ<>+9]6 if(window!=parent) !gyW15z' { O\q6T7bfRW var a = parent.document.getElementsByTagName("IFRAME"); Jm=3%H for(var i=0; i<a.length; i++) //author:meizz <b
~~X`Z { ,V!Wo4M if(a.contentWindow==window) }x6)}sz7 { LTx,oa:ma var h = document.body.scrollHeight; >8>s
K(S] if(document.all) {h += 4;} a"}ndrc* if(window.opera) {h += 1;} EFU)0IAL[ a.style.height = h; c;KMox/ } guCCu2OTA% } Wf?[GO } KWYjN
h#* } kg(
}%Ih catch (ex) modem6#x' { D1ik*mDA= alert("脚本无法跨域操作!"); >C{8}Lg-. } )~xH!%4F } ijcF[bmE if(document.attachEvent) window.attachEvent("onload", iframeAutoFit); butBS else window.addEventListener('load', iframeAutoFit, false); T#e|{ZCbq </script> Z>/
*q2 </head> ]"O*& <body> tJ7tZ~Ak <div style="width: 200; height: 400; background-color: yellow"> 0}`
-<( iframe 自适应其加载的网页(多浏览器兼容) ;xFB
/, </div> av'[k< </body> );S8`V </html>
|
|
[楼 主]
|
Posted: 2006-04-04 14:28 |
| |