The code to set iframe height to match its document's height is brief and includes just two functions.
The getDocHeight
function obtains the height of the document cross-browser for both standards and quirks mode documents. The setIframeHeight
function sets the iframe element's height to match the contained document's height.
View the source code of the main document to see these functions.
A call to the function setIframeHeight
is added to the iframe element's onload attribute:
<iframe id="ifrm" src="pages/height1.html" onload="setIframeHeight(this.id)"></iframe>