Apologies for the confusing title.
I've got a webpage with a friendly iframe in it, and the iframe contains a script tag inside it. Essentially it looks like this:
<iframe src="Javascript:'<div id=\'target\'></div><script src=\'appendStuff.js\'><\/script>'"></iframe>
appendStuff.js loads jQuery on document
, and then does an operation like the following:
doc = document; // the iframe's document
$('<h1>Loaded!</h1>').appendTo('#target', doc);
This works just fine. However, to fix another bug in appendStuff.js we needed to move jQuery and load it on window.top.document
, instead of document
which is inside the iframe.
Now, the .appendTo('#target', doc)
call silently fails, and nothing gets appended.
This is incredibly confusing because just selecting $('#target', doc)
seems to work just fine.
Does anyone know if this is actually broken, if I'm doing something wrong, or if there's some way to work around this issue?
Loaded!
').appendTo($('#target', doc));` – Alex Kudryashev Jun 21 '16 at 20:27