zoukankan      html  css  js  c++  java
  • 跨域实现IFRAME自适应高度

    <html>
    <head>
    </head>
    <body>
    <script>
    document.domain="sina.com";
    function adjustIframe(id)
     {
        var iframe = document.getElementById(id)
        var idoc = iframe.contentWindow && iframe.contentWindow.document || iframe.contentDocument;
        var callback = function () {
            var iheight = Math.max(idoc.body.scrollHeight, idoc.documentElement.scrollHeight); //取得其高
            iframe.style.height = iheight + "px";
        }
        if (iframe.attachEvent) {
            iframe.attachEvent("onload", callback);
        } else {
            iframe.onload = callback
        }
     }



         
           var ifm=document.createElement("iframe");
          ifm.src="http://test.sina.com/2.htm";
          ifm.width=1000;
           ifm.id="ok1";
           ifm.domain="sina.com";
          document.body.appendChild(ifm);
          adjustIframe("ok1");

       

    </script>

    </body>
    </html>

  • 相关阅读:
    vue 中简单路由的实现
    Vue中对生命周期的理解
    内存泄漏
    前端工程化
    exports 和 module.exports 的区别
    Nodejs的url模块方法
    MongoDB 的获取和安装
    Anjular JS 的一些运用
    移动端vconsole调试
    安装fiddler时,电脑浏览器没网
  • 原文地址:https://www.cnblogs.com/lori/p/2285458.html
Copyright © 2011-2022 走看看