Skip to content

Instantly share code, notes, and snippets.

@greatghoul
Created May 29, 2012 03:17
Show Gist options
  • Save greatghoul/2822333 to your computer and use it in GitHub Desktop.
Save greatghoul/2822333 to your computer and use it in GitHub Desktop.
iframe高度自适应
var timer = null;
function autoFrameHeight() {
timer && clearTimeout(timer);
var frame = document.getElementById('win');
var currHeight = 0;
try {
if (frame.contentDocument && frame.contentDocument.body.offsetHeight) {
frame.height = frame.contentDocument.body.offsetHeight;
} else if (frame.document && frameid.document.body.scrollHeight) {
frame.height = frame.document.body.scrollHeight;
}
} catch (e) {
} finally {
timer = setTimeout(autoFrameHeight, 30);
}
}
autoFrameHeight();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment