JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id="inpt" cols="30" rows="10"></textarea>
<div><input type="submit" value="append" id="btn" style="width:60px;height:20px;background:grey"></div><br>
<iframe id="fr" name="fr" style="width:300px;height:300px;"></iframe>
<script type="text/javascript">
var _script = document.createElement('script');
_script.type = 'text/javascript';
var iFrame = document.getElementById('fr'),
iFrameBody,
t = document.getElementById("inpt"),
btn = document.getElementById('btn');
function injectJS(content, val) {
if ( iFrame.contentDocument )
{
iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
}
else if ( iFrame.contentWindow )
{
iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
}
iFrameBody.appendChild(content);
content.innerHTML = val;
console.log(iFrameBody);
}
btn.onclick = injectJS(_script, t.value);
</script>