发布于 2026-01-06 2 阅读
0

如何检测 iframe 中内容的高度?

如何检测 iframe 中内容的高度?

假设你有一个元素iframe,你想在内容加载完毕后检测它的高度window,你会怎么做?

这种方法似乎令人满意,但我感觉这个领域可能存在一些特殊情况和陷阱,所以我非常乐意接受不同的方法。

IFRAME您可以使用以下方法检索内容的高度contentWindow.document.body.scrollHeight

加载完成后IFRAME,您可以通过以下步骤更改高度:

<script type="text/javascript">
  function iframeLoaded() {
      var iFrameID = document.getElementById('idIframe');
      if(iFrameID) {
            // here you can make the height, I delete it first,
文章来源:https://dev.to/ben/how-would-you-go-about-detecting-the-height-of-content-within-an-iframe-14d8