Reference Information. I need to load ad scripts after loading the DOM. Since many scripts use document.write () and other potentially bad functions to run after loading the DOM, I want to load scripts inside an iframe.
So, when an ad should be shown, an event is fired that performs the following actions:
var iframe = document.createElement('iframe');
iframe.setAttribute('id', 'iframeId');
iframe.setAttribute('src', 'about:blank');
var adContainer = document.getElementById('AdContainer');
adContainer.appendChild(iframe);
var val = '<html><head></head><body>';
val += '<scr' + 'ipt type="text/javascript" src="' + url + '"></scr' + 'ipt>';
val += '</body></html>';
If I do not assign the html and body val tags, the script is automatically added to the iframe header and cannot be executed in FF. In IE, the script is not executed with or without head / body / html tags.
var doc = iframe.contentWindow || iframe.contentDocument;
if (doc.document){
doc = doc.document
}
doc.open();
doc.write(val);
doc.close();
: <script> <iframe> , script ?. jquery iframe, script .
, , FF Webkit. IE script. script , . script iframe, -? IE script?
, script iframe, , . , appendChild() iframe, script, script iframe DOM, , , .