jquery getscript for iframe object
I've got a dynamically created iframe that I'm trying to add a script to. For example:
var iframe = document.createElement("iframe");
I'd like to inject javascript into this iframe. I've got this working without using jquery by creating a script element under the iframe object and adding callbacks to this script object via the readystate & onReadyState events. Now I'd like to try the same thing with jquery.
However if I just do:
$.getScript(url,function() {
myCallback();
});
My script(s) get added to the current document, and references from the iframe object are broken. How can I call getscript on an iframe object?
Tried this which didn't开发者_开发技巧 work:
var elementID = $(element).attr('id');
$('iframe#' + elementID).getScript(url, function(){
myCallback();
});
The only way .getScript
would work is if you executed it on the iframe as jquery automatically downloads and adds the script to the current document
精彩评论