Created
June 7, 2011 14:30
-
-
Save Phil-B/1012359 to your computer and use it in GitHub Desktop.
Auto-resize a same-domain iframe to the height of it's content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This presumes that the iframe content is static, so the resize event isn't used