main.htm:
iframe自适应加载的页面高度
child.htm:
iframe 自适应其加载的网页(多浏览器兼容) <script> <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 h = document.body.scrollHeight; <BR> if(document.all) {h += 4;} <BR> if(window.opera) {h += 1;} <BR> a[i].style.height = h; <BR> } <BR> } <BR> } <BR> } <BR> catch (ex) <BR> { <BR> alert("脚本无法跨域操作!"); <BR> } <BR> } <BR> if(document.attachEvent) window.attachEvent("onload", iframeAutoFit); <BR> else window.addEventListener('load', iframeAutoFit, false); <BR> </script>
iframe 自适应其加载的网页(多浏览器兼容)