[jQuery] Exec'ing JS In load()ed content for IE
I'm using jQuery's load() function in order to pull content from the
server and stick it into a div.
This content has both html + javascript inside it, and I need to get
the javascript actually evaluated for IE6+7.
Firefox handles javascript fine for both inline + externally
referenced libraries, eg:
<script language="javascript" src="/path/to/lib.js" type="text/
javascript"></script>
and
<script language="javascript">
alert('some js code running here!');
</script>
The above does not work with both IE6 + IE7.
If you look at mootools' api, they include a "evalScripts" flag to
eval/execute javascript inside the returned content:
http://docs.mootools.net/Remote/Ajax.js
They make use of IE's "execScript" function in order to do this.
Sample code:
onComplete:
-----
scripts = (this.options.evalScripts) ? '' : null;
this.response.text = this.response.text.replace(/<script[^>]*>([\s
\S]*?)<\/script>/gi, function(){
if (scripts !== null) scripts += arguments[1] + '\n';
return '';
});
if (scripts) (window.execScript) ? window.execScript(scripts) :
window.setTimeout(scripts, 0);
-----
Another blog entry about execScript:
http://ajaxian.com/archives/evaling-with-ies-windowexecscript
Questions:
* Is there a way to handle this neatly with jQuery?
* Is an "evalScripts" flag planned for jQuery's load() function?
* Is there a better way to handle content containing mixed
javascript/css/html?
thanks in advance,
SM