You must ensure that the jQuery script is loaded before trying to use eval code that uses jQuery syntax. Take a look at this topic fooobar.com/questions/398211 / ....
function scriptTag(src, callback) { var s = document.createElement('script'); s.type = 'text/' + (src.type || 'javascript'); s.src = src.src || src; s.async = false; s.onreadystatechange = s.onload = function() { var state = s.readyState; if (!callback.done && (!state || /loaded|complete/.test(state))) { callback.done = true; callback(); } };
Change your code in the callback function as shown below and everything should be fine.
var js = ""; // JavaScript or jQuery code here scriptTag("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js", function(){ frames[0].window.eval(js); });
I tested it here http://jsfiddle.net/SFUbg/2/ . I donβt know why in this function the scriptTag doc
used instead of the document, since it is not equivalent, so I changed it.
source share