Hello.
There is an iframe that is created as a result of loading the page.
var object_preview = $('#preview'); var iframe = $('<iframe id="preview_frame">'), iframe_body, iframe_head; object_preview.html(iframe); setTimeout(function() { var doc = iframe[0].contentWindow.document; iframe_body = $('body', doc); iframe_head = $('head', doc); }, 1);
When a certain button is clicked, the JS code (jQuery) is inserted into the head tag of this iframe, which must be executed inside the iframe tree.
Button click handler:
$('#run').click(function() { iframe_body.append('<script type="text/javascript">\ $(document).ready(function() {\ $(".test").click(function() { alert(true); });\ });\ </script>'); });
At the moment the code is not executed, how can this be implemented?
The element with the test class is inside the iframe tree; The code must also be executed inside the iframe, and not on the entire page.
HTML structure:
document.createElement('script')
and add it with the child to the iframe head, - zb '25