1. 程式人生 > >iframe交互(一)父頁面自動高度

iframe交互(一)父頁面自動高度

name this vsp 父頁面 scroll 是否 lin () bsp

//父頁面源碼
<body style="border:1px solid red;width:200px;height:500px;" onload="IFrameResize()">
    <script>
        function IFrameResize() {
            //alert(this.document.body.scrollHeight); //彈出當前頁面的高度 
            var obj = parent.document.getElementById("childFrame"); //取得父頁面IFrame對象 
            
//alert(obj.height); //彈出父頁面中IFrame中設置的高度 obj.height = this.document.body.scrollHeight; //調整父頁面中IFrame的高度為此頁面的高度 } </script> <script type="text/javascript" src="./auto-height.js"></script> </body> //子頁面源碼 <body> <IFRAME border=0 marginWidth=0 frameSpacing=0
marginHeight=0 src="iframe.html" frameBorder=0 noResize scrolling="no" width=100% height=100% vspale="0" id="childFrame"></IFRAME> <!-- <iframe id="iframe" name="asd" src="iframe.html" onload="loadIframe(this)" height="100" frameborder="0" style="border:1px solid blue"> </iframe> --> <script type="
text/javascript"> function loadIframe(doc) { console.log(doc.contentWindow.document); } </script> </body>

註意:調試時註意是否是本地啟動,還是基於代理服務器。本地啟動會觸發作用於問題導致錯誤

iframe交互(一)父頁面自動高度