I'm using jQuery to make an ajax request, and everything is working as expected. But it's evaluating the scripts in the wrong context.
I have an iframe (same domain, no worries here), and I'm trying to get the scripts to eval in the context of the iframe, instead of where the ajax request was made -- eg. a different frame.
I figured I could tell ajax not to eval the scripts, and I would do the work myself to eval them in the right context. Any ideas, or ways to disabled the automatic eval?
Edit
So, I was somewhat wrong about the initial question.. The scripts are not evaluated when loaded, but rather when the content is being placed in the document. You can see this by testing the example:
$('#some_element').html('<span>content</span><script>alert(window)</script>');
Now, when doing this from a different frame, the evaluation happens in the scope of where you're calling, not the element you're inserting content into.
I ended up setting the content without using jQuery, and then finding/evaling any script tags:
element.get(0).innerHTML = data;
element.find('script').each(function() {
otherWindow.eval(this.innerText);
});
Final Update
I ended up tracking it down to the source, and overriding it from there.. the following is coffeescript, but you can get the idea. I chose to override it because for my usage, this should never happen in the top window, but is expected in the iframe content.
$.globalEval = (data) -> (iframeWindow.execScript || (data) -> iframeWindow["eval"].call(iframeWindow, data))(data) if (data && /\S/.test(data))