Friends, I shoveled half of the Internet, but I could not find a working solution. In general, in the iframe you need to load the site and take its height, tried the iFrame Resizer plug-in, the height did not change, the standard 150px, tried easyXDM — an error, tried this thing

function doIframe() { o = document.getElementsByTagName('iframe'); for (i = 0; i < o.length; i++) { if (/\bautoHeight\b/.test(o[i].className)) { setHeightIframe(o[i]); $(o[i]).load(function() { doIframe(); }); } } } function setHeightIframe(e) { if (e.contentDocument) { $(e).height(e.contentDocument.body.offsetHeight + 35); } else { $(e).height(e.contentWindow.document.body.scrollHeight); } } 
  • Describe in detail and post your code - neoman
  • Show current non-working solution. Do you need to get the height of the entire loaded page? - tutankhamun
  • Yes, there are a lot of solutions, but they do not work for me, the main gag is that you need to upload content from another domain - user183678

1 answer 1

If I understand your question correctly: you want to load some content into the iframe , but the problem is that you don’t know the height of the content being downloaded, and therefore don’t know what height the iframe should be.

I came across a similar problem when we were developing widgets, for example for edx .

You can not set the height of the iframe in the "insides" of the iframe . Alternatively, you can calculate the height in the "inside" of the iframe and transfer it to js which connects the iframe in the parent window. In order to link the js in the "insides" of the iframe and js in the parent window, we used the Mozilla jschannel library .

Please note that the height of the loaded content will not always be the same, changes in the height of the browser window (if you have a responsive page) and user actions inside the iframe can result in a change in height - all these cases can be solved by adding new events to jschannel .

If you do not have access to the content of the iframe and you want to get its height, unfortunately, I do not know what you can advise, and in general it is possible.