如何使用激励js查找iFrame内容窗口的高度?

问题描述

我正在浏览stimulus文档,并决定在这个框架上摆弄。当我发现iframe内容窗口的高度时,我发现了一个奇怪的行为。我不确定是否出错。

<div data-controller="preview">
  <iframe data-target="preview.iFrame">...code</iframe>
</div>
export default class extends Controller {
  static targets = ['iFrame'];

  initialize() {
    const frameHeight = this.iFraMetarget.contentwindow.document.body
      .scrollHeight;
    this.setHeight(frameHeight);
  }

  setHeight(height) {
    console.log(height)
  }
}

当前console记录8px作为iframe的高度,这显然是错误的。当我使用chrome控制台进行调试时,我得到了正确的高度,即629px

有人可以解释如何解决此问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)