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" onclick="injectJS();"></div><br>
<iframe id="fr" name="fr" style="width:300px;height:300px;"></iframe>
JavaScript
var _script = document.createElement('div');
//_script.type = 'text/javascript';
var iFrame = document.getElementById('fr'),
iFrameBody,
t = document.getElementById("inpt"),
btn = document.getElementById('btn');
window.injectJS =function () {
var content = _script;
var val = document.getElementById('inpt').value;
if ( iFrame.contentDocument )
{
iFrameBody =iFrame.contentDocument.getElementsByTagName('body')[0];
}
else if ( iFrame.contentWindow )
{
iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
}
content.innerHTML = val;
iFrameBody.appendChild(content);
console.log(iFrameBody);
}