Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-resize a same-domain iframe to the height of it's content
(function($) {
$.fn.extend({
iFrameAutoHeight: function() {
return this.each(function() {
var obj = $(this);
obj.height(0); //avoid flash at full height
if (obj.contents().find('body').height() > 0) { // already loaded - from cache (ie only)
resize(obj);
} else {
obj.load(function() {
resize(obj);
})
}
});
function resize(obj) {
obj.height(obj.contents().find('body').height());
}
}
});
})(jQuery);
@Phil-B

This comment has been minimized.

Show comment
Hide comment
@Phil-B

Phil-B Jun 7, 2011

This presumes that the iframe content is static, so the resize event isn't used

Owner

Phil-B commented Jun 7, 2011

This presumes that the iframe content is static, so the resize event isn't used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment