1
有谁知道如何在Chrome中动态添加脚本?我复制了以下在FF 3.0和IE7中运行的代码,但不是Chrome。在Chrome中未动态添加脚本
function include_dom(script_filename) {
var html_doc = document.getElementsByTagName('head').item(0);
var js = document.createElement('script');
js.setAttribute('language', 'javascript');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', script_filename);
html_doc.appendChild(js);
return false;
}
var included_files = new Array();
function include_once(script_filename) {
if (!in_array(script_filename, included_files)) {
included_files[included_files.length] = script_filename;
include_dom(script_filename);
}
}
function in_array(needle, haystack) {
for (var i = 0; i < haystack.length; i++) {
if (haystack[i] == needle) {
return true;
}
}
return false;
}
我可以通过运行看到附加到所述头元件的代码:
`document.getElementsByTagName( '头')项目(0).innerHTML;
在Chrome的检查器中,但是我看不到任何在我的HTTP嗅探器中被请求的脚本。