zoukankan      html  css  js  c++  java
  • iframe自适应内容高度

    <!--
     * @Description: 描述
     * @Version: 1.0
     * @Autor: Nanke_南柯
     * @Date: 2020-11-03 14:09:04
     * @LastEditors: Nanke_南柯
     * @LastEditTime: 2020-11-03 14:09:05
    -->
    <!DOCTYPE html>
    <html lang="sv">

    <head>
        <meta charset="utf-8" />
        <title>Iframe height demo</title>
        <style media="screen,print">
            #body {
                 70em;
                max- 100%;
                margin: 0 auto;
            }

            iframe {
                 100%;
                margin: 0 0 1em;
                border: 0;
            }
        </style>
        <script>
            /*
             * When the iframe is on a different subdomain, uncomment the following line
             * and change "example.com" to your domain.
             */
            // document.domain = "example.com";
            function setIframeHeight(iframe) {
                if (iframe) {
                    var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
                    if (iframeWin.document.body) {
                        iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
                        console.log(iframeWin.document.documentElement.scrollHeight , iframeWin.document.body.scrollHeight);
                    }
                }
            };
        </script>
    </head>

    <body>
        <div id="body">
            <h1>Iframe height demo</h1>
            <h2><code>iframe</code> <strong>with</strong> height adjustment</h2>
            <iframe src="iframe高度自适应-src.html"
                frameborder="0"
                id="external-frame" onload="setIframeHeight(this)"></iframe>
        </div>
    </body>

    </html>
  • 相关阅读:
    BZOJ3501 : PA2008 Cliquers Strike Back
    BZOJ3500 : PA2008 Cliquers
    BZOJ2280 : [Poi2011]Plot
    BZOJ2924 : [Poi1998]Flat broken lines
    BZOJ2911 : [Poi1997]The Number of Symmetrical Choices
    BZOJ2612 : [Poi2003]Sums
    BZOJ4025 : 二分图
    BZOJ2213 : [Poi2011]Difference
    BZOJ2215 : [Poi2011]Conspiracy
    BZOJ2278 : [Poi2011]Garbage
  • 原文地址:https://www.cnblogs.com/NanKe-Studying/p/13920003.html
Copyright © 2011-2022 走看看