I've got the logic working to append into my iframe from the parent
this works:
$('#iframe').load(function() {
$(this).contents().find('#target').append('this text has been inserted into the iframe by jquery');
});
this doesn't
$('#iframe').load(function() {
$(this).contents().find('body').append('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>');
});
.lf
The problem is something to do with the inserted script tags not being escaped properly. Half of the javascript is becomes visible in the html, like the first script tag has been abruptly ended.
I'm a bit surprised that isn't working[Edit: No longer surprised at all, see mtrovo's answer.]...but here's what I do, which ismostlynon-jQuery per your comment below but still quite brief:Off-topic: I really wouldn't give an iframe (or anything else) the ID "iframe". That just feels like it's asking for trouble (IE has namespace issues, and while I'm not aware of it confusing tag names and IDs, I wouldn't be completely shocked). I've used "theframe" above instead.
Maybe the error is with your string, never create a string in javascript with a literal < /script> in it.
Warning: loading script in this manner would make scripts running in main window context i.e.: if you use window from somescript.js, it would be NOT iframe's window!
To be able to use iframe context inject script with this: