Note that there are some explanatory texts on larger screens.

plurals
  1. POdocument.write from external script not executed in an iframe created with javascript / jQuery
    primarykey
    data
    text
    <p>I want to add and remove an iframe to a document using javascript / jquery (actually the iframe should be added and also removed if the user chooses to close it).</p> <p>In this iframe, I have to include an external script using the element, script that contains basically generated content displayed using document.write (ad rotator).</p> <p>The problem I have is that when the iframe is loaded, the element is included but its content is not "interpreted", so that the content is not write with document.write.</p> <p>I don't know what I am missing here.</p> <p>Here is what I tried (inspired from other answers on SO):</p> <p>html:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;script src="jquery-10.2.js"&gt;&lt;/script&gt; &lt;script src="frame.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt;Some content&lt;/div&gt; &lt;div id=myFrameContainer&gt;​&lt;/div&gt;​​​​​​​ &lt;/body&gt; &lt;/html&gt; </code></pre> <p>frame.js:</p> <pre><code>$(document).ready(function(){ $('&lt;iframe&gt;&lt;/iframe&gt;', {name:"myFrame",id:"myFrame"}) .css("height", 300) .css("width", 500) .load(function() { $(this).contents().find("body") .append('&lt;scr' + 'ipt type="text/javascript" src="http://example.com/rotator.php?affid=12345"&gt;&lt;/scr' + 'ipt&gt;'); }).appendTo("#myFrameContainer"); }); </code></pre> <p>I also tried to append the element to the head and also without any success.</p> <p>On top of this, I can see the content generated by the external script in Firebug (but maybe this is totally normal and has nothing to do with my question).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload