let script=document.createElement('script');
script.innerText=`your script`
document.querySelector('iframe').appendChild(script)
var iframe = document.getElementById('frameID'),
iframeWin = iframe.contentWindow || iframe,
iframeDoc = iframe.contentDocument || iframeWin.document;
window.hello = function () {
alert('hello from owner!');
};
$(iframeDoc).ready(function (event) {
iframeDoc.open();
iframeDoc.write('iframe here');
iframeDoc.write('<script>alert("hello from iframe!");</script>');
iframeDoc.write('<script>parent.hello();</script>');
iframeDoc.close();
});