Created
April 7, 2018 09:59
-
-
Save corerman/c79a5a06a2b35d105809bf8b140b94ee to your computer and use it in GitHub Desktop.
JS:iframe 自动适应内容高度
This file contains hidden or 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 reinitIframe() { | |
| var iframe = document.getElementById("main_iframe"); | |
| try { | |
| var bHeight = iframe.contentWindow.document.body.scrollHeight; | |
| var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; | |
| var height = Math.max(bHeight, dHeight); | |
| iframe.height = height; | |
| } catch (ex) {} | |
| } | |
| window.setInterval("reinitIframe()", 200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment