var iframe = $('<iframe></iframe>').attr({id:'iframe', width:'200',height:'200', border:'1'});
$(document.body).append(iframe);
$('#iframe').attr({src:'doc-iframe.php'});
$('#iframe').load(function(){
$('<div></div>', this.contentWindow.document).append(function(){
$(this).append('<form name="test" id="test"><input name="name" value="Serban"><input type="submit"></form> <sc'+'ript>console.log(window); document.test.submit();</sc'+'ript>');
});
});
The code above is executed on the page http://test.local/doc.html It tries to load some content into:
<iframe id="iframe" src="doc-iframe.php"></iframe>
The problem is that document.test.submit() is not executed inside the context of #iframe and document points to doc.html instead of doc-iframe.php.
How can i execute this code inside the context of #iframe?
Consider that the HTML code inside append() is the result from an html AJAX response that i cannot control.