Resize iFrame to its content

Submitted by:David Villa

Date added:13 December, 2015

Category:JavaScript

Bind onload function to the iFrame and set the size of the iFrame to the iFrames loaded content. In the example jQuery is used.

Tags: iframe , resize iframe

Code Snippet:

    $("#modalIFrame").bind('load',
function () {
var newheight,
newwidth;

newheight = this.contentWindow.document.body.scrollHeight;
newwidth = this.contentWindow.document.body.scrollWidth;

$(this).height(newheight);
$(this).width(newwidth);
}
);

$("#modalIFrame").attr('src', url);
 
 

Comments