Skip to content

Instantly share code, notes, and snippets.

@zachberry
Last active June 8, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachberry/fe57deaaf1b06c9e2d239dd8661e4e9d to your computer and use it in GitHub Desktop.
Save zachberry/fe57deaaf1b06c9e2d239dd8661e4e9d to your computer and use it in GitHub Desktop.
Get HTML from a React component and inject it into an iframe
class TestPage extends React.Component {
render() {
return (
<body>...</body>
)
}
}
class SomeComponent extends React.Component {
injectTestPage() {
let div = document.createElement('div')
ReactDOM.render(<TestPage />, div)
this.refs.iframe.contentDocument.body.outerHTML = div.outerHTML
}
render() {
return (
<div>
<iframe ref="iframe" />
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment