I am working with iframe tag for displaying ads.
I am using below code for it -
<iframe></iframe> JS -
var iframe = document.getElementById('abc'); var doc = iframe.contentDocument ? iframe.contentDocument :(iframe.contentWindow ? iframe.contentWindow.document : iframe.document) doc.open(); doc.write('<scr'+'ipt src=""></scr' + 'ipt>'); doc.close(); I tried it on normal HTML page and body gets blank in inner document of Iframe, but same code I execute in codepen it get executed, and body filled with executed script.
I needed solution or alternate solution to make it work.
1 Answer
Try oldskool
<iframe name="iframe" src="emptypage.html"></iframe> JS -
window.onload=function() { var iframe = window.frames['iframe']; var doc = iframe.document; doc.write('<scr'+'ipt src=""></scr' + 'ipt>'); doc.close(); } Here is what I see now I add the script to another iframe raw and turn off ad blocking so it seems to work.
23



