有没有办法加载一个js文件,里面有document.write?如何在createElement中使用document.write加载JavaScript文件?
即:
(function(){
var test = document.createElement('script');
test.type="text/javascript";
test.src="http://xxxxxxxxxxx/test.js";
document.getElementsByTagName('head')[0].appendChild(test);
})();
test.js:
document.write('test !');
它总是返回有关文件撰写的异步警报错误...
我想通了,如果我这样做:
test.js:
document.getElementsByTagName('body')[0].innerHTML = 'test !';
它的工作原理!
但在我的情况下,我不能访问js文件,那么我想知道是否有办法做到这一点?或者我需要用php curl做一个交叉。
谢谢。
在加载脚本之前,您可以尝试覆盖document.write函数。 – Bergi 2012-07-08 23:41:32