DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

Dynamically change the iframe height from inside

🤔 Situation

Your page is embedded to an iframe which ID is parent-iframe, and you want to change the height by your page content.

<html>
  <head>
  </head>
  <body>
    <div>
      <iframe src="https://your.html" id="parent-iframe"></iframe>
    </div>
  </body>
</html>

🦄 Solution

Run a script from inside to the iframe, when the page is ready.

  <head>
    <script type="text/javascript">
    $(document).ready(function() {
    $("#parent-iframe", window.parent.document).height(document.body.scrollHeight);
    });
    </script>
  </head>

🔗 Parent Note

Top comments (0)