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>
  • 相关阅读:
    lea
    DIV指令
    html基础
    浮点计算结果误差,以及解决方法
    java的threadLocal类
    java多线程基础总结
    sql反模式读书笔记 (持续更新)
    pdb 调试初步
    面向对象设计原则与总结 (持续更新)
    @servcie注解基本用法
  • 原文地址:https://www.cnblogs.com/NanKe-Studying/p/13920003.html
Copyright © 2011-2022 走看看