Skip to content

Instantly share code, notes, and snippets.

@yulanggong
Created March 8, 2013 08:08
Show Gist options
  • Save yulanggong/5114926 to your computer and use it in GitHub Desktop.
Save yulanggong/5114926 to your computer and use it in GitHub Desktop.
iframe Auto Height
var iframeAutoHeight = function(iframe){
var src
setInterval(function(){
if (src != iframe.contentWindow.location.href){
setHeight()
src = iframe.contentWindow.location.href
}
}, 200)
function setHeight(){
try{
iframe.height = 400
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch(e){}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment