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


 

//父頁面源碼
<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>

 

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM