Created
October 6, 2014 14:30
-
-
Save xl1/de5b20204d5630367ed2 to your computer and use it in GitHub Desktop.
srcdoc 便利事例
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
html = ' | |
<!doctype html> | |
<title>test</title> | |
<body> | |
foo bar | |
</body> | |
' | |
ifr = document.createElement 'iframe' | |
document.body.appendChild ifr | |
ifr.src = "data:text/html,#{html}" | |
ifr.onload = -> | |
try | |
ifr.contentDocument # SecurityError on Chrome! | |
catch e | |
console.log e | |
ifr.srcdoc = html | |
ifr.onload = -> | |
ifr.height = ifr.contentDocument.documentElement.offsetHeight # OK!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
でいいのでは