Skip to content

Instantly share code, notes, and snippets.

@xl1
Created October 6, 2014 14:30
Show Gist options
  • Save xl1/de5b20204d5630367ed2 to your computer and use it in GitHub Desktop.
Save xl1/de5b20204d5630367ed2 to your computer and use it in GitHub Desktop.
srcdoc 便利事例
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!!!
@xl1
Copy link
Author

xl1 commented Oct 20, 2014

doc = ifr.contentDocument
doc.open()
doc.write html
doc.close()

でいいのでは

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment