关于iframe高度自适应的问题

图片描述
用本地的路径的话,iframe不能高度自适应

图片描述
用localhost的就可以,为什么?

    function reinitIframe() {
        var iframe = document.getElementById("pcIframe");
        try {
            var bHeight = iframe.contentWindow.document.body.scrollHeight;
            var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
            var height = Math.max(bHeight, dHeight);
            iframe.height = height;
            console.log(iframe.height);
        } catch (ex) { }
    }
阅读 2.1k
1 个回答

F12调试看看,本地方式打开可能根本就没有加载JS

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题