main.htm: iframe自适应加载的页面高度 child.htm: iframe 自适应其加载的网页(多浏览器兼容) <script> <BR> <!-- <BR> function iframeAutoFit() <BR> { <BR> try <BR> { <BR> if(window!=parent) <BR> { <BR> var a = parent.document.getElementsByTagName("IFRAME"); <BR> for(var i=0; i<a.length; i++) //author:meizz <BR> { <BR> if(a[i].contentWindow==window) <BR> { <BR> var h1=0, h2=0; <BR> a[i].parentNode.style.height = a[i].offsetHeight +"px"; <BR> a[i].style.height = "10px"; <BR> if(document.documentElement&&document.documentElement.scrollHeight) <BR> { <BR> h1=document.documentElement.scrollHeight; <BR> } <BR> if(document.body) h2=document.body.scrollHeight; <br><br> var h=Math.max(h1, h2); <BR> if(document.all) {h += 4;} <BR> if(window.opera) {h += 1;} <BR> a[i].style.height = a[i].parentNode.style.height = h +"px"; <BR> } <BR> } <BR> } <BR> } <BR> catch (ex){} <BR> } <BR> if(window.attachEvent) <BR> { <BR> window.attachEvent("onload", iframeAutoFit); <BR> //window.attachEvent("onresize", iframeAutoFit); <BR> } <BR> else if(window.addEventListener) <BR> { <BR> window.addEventListener('load', iframeAutoFit, false); <BR> //window.addEventListener('resize', iframeAutoFit, false); <BR> } <BR> //--> <BR> </script>
iframe 自适应其加载的网页(多浏览器兼容,支持XHTML) |
======================================
iframe标签的高度怎么样才能自适应src的页面?
例如:
这个iframe的高度怎么能自适应agree.htm的高度600?
不要告诉我设为height=600,因为这个iframe要应用几个高度不同的页面!
谢谢,找到了
<script> <BR>function autoResize() <BR>{ <BR>try <BR>{ <BR>document.all["test"].style.height=test.document.body.scrollHeight <BR>} <BR>catch(e){} <BR>} <BR></script>