Reputation: 908
// resize myiframe base on content height
$('.myiframe').contents().find('body').css({"min-height": "100", "overflow" : "hidden"});
setInterval( "$('.myiframe').height($('.myiframe').contents().find('body').height() + 20)", 1 );
the above code will automatically resize the iframe's height based on content height. The problem is, how do I set the minimum height of the iframe to 500px, if the content height is less than 500px ?
Upvotes: 1
Views: 2894
Reputation: 46008
You can use Math.max()
.
setInterval( function(){
var height = $('.myiframe').contents().find('body').height() + 20;
$('.myiframe').height(Math.max(height, 500));
}, 1 );
PS. You've using setInterval
which will run your code every millisecond until the page is unloaded. Change to setTimeout
or use clearInterval
.
Upvotes: 2