Well most results seem to point at it being a security/permission issue but a lot of that is related to IE7+ and this is IE6 (thanks IT!

).
If I right click the page and select refresh, then it works properly, so I believe that when you use document.write it never downloads and inserts the external script. I'm not convinced that's actually related to security/permissions though.
Maybe this means you could fix it by writing the content to the document and then loading/refreshing it, but probably not.
I've also found an ugly nasty work-around hack, thanks to a poster on
Stack Overflow (Not that their solution is those adjectives, but rather having to use it here is all those things.

)
So this works:
Code: Select all
"HTML-2"
$html = <<<HEREDOC
<HTML>
<HEAD>
<SCRIPT type="text/javascript">
function loadScript(url, completeCallback) {
var done = false;
var head = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.src = url;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
script.onload = script.onreadystatechange = null;
completeCallback();
}
};
head.appendChild(script);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
loadScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', function() {
document.write(typeof jQuery);
});
</SCRIPT>
</BODY>
</HTML>
HEREDOC;
$a = HTML("$html");
The first solution from that thread might work, but I wasn't haven't success. Presumably, it was executing the rest of my script before it had completely downloaded and inserted jQuery.
It's not pretty but it hopefully means I can accomplish what I wanted without having to resort to writefile.