document.write from external script not executed in an iframe created with javascript / jQuery -
i want add , remove iframe document using javascript / jquery (actually iframe should added , removed if user chooses close it).
in iframe, have include external script using element, script contains generated content displayed using document.write (ad rotator).
the problem have when iframe loaded, element included content not "interpreted", content not write document.write.
i don't know missing here.
here tried (inspired other answers on so):
html:
<!doctype html> <html> <head> <title></title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script src="jquery-10.2.js"></script> <script src="frame.js"></script> </head> <body> <div>some content</div> <div id=myframecontainer></div> </body> </html>
frame.js:
$(document).ready(function(){ $('<iframe></iframe>', {name:"myframe",id:"myframe"}) .css("height", 300) .css("width", 500) .load(function() { $(this).contents().find("body") .append('<scr' + 'ipt type="text/javascript" src="http://example.com/rotator.php?affid=12345"></scr' + 'ipt>'); }).appendto("#myframecontainer"); });
i tried append element head , without success.
on top of this, can see content generated external script in firebug (but maybe totally normal , has nothing question).
document.write
available while page being loaded or after calling document.open
. cannot used script appended later, you're doing in frame.js
.
Comments
Post a Comment