您的位置首页生活快答

JS代码怎么实现iframe自适应高度?

JS代码怎么实现iframe自适应高度?

的有关信息介绍如下:

JS代码怎么实现iframe自适应高度?

html head titleiframe自适应网页-学无忧(www.xue51.com)/title script type=text/javascript //自动调整iframe框架的方法function iframeAuto() { try { if(window!=parent) { //定位需要调整的frame框架(在父级窗口中查找)var a = parent.document.getElementsByTagName(IFRAME); for(var i=0; ia.length; i++){ if(a[i].contentWindow==window) { var h1=0, h2=0; a[i].parentNode.style.height = a[i].offsetHeight +px; a[i].style.height = 10px; //首先设置高度为10px,后面会修改if(document.documentElementdocument.documentElement.scrollHeight) { h1=document.documentElement.scrollHeight; } if(document.body) h2=document.body.scrollHeight; var h=Math.max(h1, h2); //取两者中的最大值if(document.all) {h += 4;} if(window.opera) {h += 1;} //调整框架的大小a[i].style.height = a[i].parentNode.style.height = h +px; } } } } catch (ex){} } //事件绑定的方法,支持IE5以上版本if(window.attachEvent) { window.attachEvent(onload, iframeAuto); } else if(window.addEventListener) { window.addEventListener('load', iframeAuto, false); } //-- /script /head body table border=1 width=200 style=height: 400px; background-color: gray tr tdiframe 自适应其加载的网页/td /tr /table /body /html