How to Auto Height an Iframe using JavaScript

Tara Prasad Swain HTML5, JavaScript, jQuery

In this article I will explain how to adjust the iframe height with the content with the help of JavaScript. This is very useful when the content is dynamic and reloads or AJAX load content in an iframe.

Use below code to resize the iframe height with the content.

function resizeIframe() {
var obj = jQuery('#iframeid')[0];
var ih = obj.contentWindow.document.body.scrollHeight; = ih + 'px';

To make it adjust with dynamic content on the fly, use interval.

setInterval(function () {
}, 1000);

Hope this helps

Share this Post