跨域实现IFRAME自适应高度

女生的网名这么多〃 提交于 2020-01-30 08:42:20

<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>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!