Created
May 29, 2012 03:17
-
-
Save greatghoul/2822333 to your computer and use it in GitHub Desktop.
iframe高度自适应
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
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