This question already has an answer here:
For example:
<iframe name="Stack" src="http://stackoverflow.com/" width="740"
frameborder="0" scrolling="no" id="iframe"> ...
</iframe>
I want it to be able to adjust its height according to the contents inside it, without using scroll.
I've had problems in the past calling iframe.onload for dynamically created iframes, so I went with this approach for setting the iframe size:
iFrame View
Main View
(this is only going to work if both views are in the same domain)
Avoid inline JavaScript; you can use a class:
And reference it with jQuery:
Try this for IE11
this is not working for chrome. But working for firefox.
You can use this library, which both initially sizes your iframe correctly and also keeps it at the right size by detecting whenever the size of the iframe's content changes (either via regular checking in a
setInterval
or viaMutationObserver
) and resizing it.https://github.com/davidjbradshaw/iframe-resizer
This works with both cross and same domain iframes.