Sivad Posted June 29, 2022 Report Share Posted June 29, 2022 Hello, Is it possible to resize iframe height based on the content? Quote Link to comment Share on other sites More sharing options...
0 April Posted June 29, 2022 Report Share Posted June 29, 2022 Hi Sivad, It is possible by pasting this script on your footer: <script> var iframes= document.querySelectorAll("iframe"); //get all iframes iframes.forEach(function f1(elem){ //loop into each iframe elem.addEventListener("load", function f2(){ //check if each iframe has 'loaded' elem.style.height =elem.contentWindow.document.body.scrollHeight + 'px'; //assign the height //if you want to add more to the height, you can do //elem.contentWindow.document.body.scrollHeight + NUMBER + 'px'; }); }); </script> If you want to do this on only one iframe when you have multiple: 1.) Assign an ID to the iframe, i.e. id="target" 2.)Use the following script <script> var iframe1 = document.getElementById("target"); //get iframe with id="target" iframe1.addEventListener("load", function tx(){ iframe1.style.height =iframe1.contentWindow.document.body.scrollHeight + 'px'; }); </script> Please note that this code will not work with a SEARCH FORM as it only resizes WHEN the contents of the iframe have been loaded. Hope this helps. Quote Link to comment Share on other sites More sharing options...
0 Kurumi Posted July 8, 2022 Report Share Posted July 8, 2022 Hi @Sivad - you can check this forum post as well for the solution: Quote Link to comment Share on other sites More sharing options...
Question
Sivad
Hello,
Is it possible to resize iframe height based on the content?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.