How to obtain the height of the content in iframe and open the height of the parent container

the iframe height on the top of the page does not stretch with the content height, resulting in multiple scroll bars on the page

Mar.04,2022

https://blog.csdn.net/qq_3060.


1. Give the current iframe a min-height;
2, and then js controls the height for adaptive layout, as follows:

function setIframeHeight(iframe) {
  if (iframe) {
    var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
    if (iframeWin.document.body) {
      iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
    }
  }
};
window.onload = function () {
  setIframeHeight(document.getElementById('-sharpID'));// -sharpIDiframeid
};
Menu