設施的跨瀏覽器測試腳本:
var CFLoad = {
fScript : null,
isFileReady : function (v) {
return (! v || v == "loaded" || v == "complete" || v == "uninitialized");
},
js : function(src,cb,attrs) {
var s = document.createElement("script"),
done = !1, i;
s.src = src;
s.type = "text/javascript";
for (i in attrs) {
s.setAttribute(i, attrs[ i ]);
}
s.onreadystatechange = s.onload = function() {
if (! done && CFLoad.isFileReady(s.readyState)) {
done = !0;
if(cb) cb(s);
s.onload = s.onreadystatechange = null;
}
};
window.setTimeout(function() {
if(!done) {
done = !0;
if(cb) cb(s,1);
}
}, 5000);
if(this.fScript===null) this.init();
this.fScript.parentNode.insertBefore(s, this.fScript);
},
css : function(href,cb,attrs) {
var l = document.createElement("link"),i;
l.href = href;
l.rel = "stylesheet";
l.type = "text/css";
for (i in attrs) {
l.setAttribute(i, attrs[i]);
}
if(this.fScript===null) this.init();
this.fScript.parentNode.insertBefore(l,this.fScript);
if(cb) window.setTimeout(cb, 0);
},
init : function() {
this.fScript = document.getElementsByTagName("script")[ 0 ];
}
};
使用
CFLoad.js("http://code.jquery.com/jquery-1.8.3.js", function (script_tag, failed) {
if(!failed) {
CFLoad.js("http://code.jquery.com/ui/1.9.2/jquery-ui.js", function(s, f) {
if(!f) {
alert("Loaded");
js13 = jQuery.noConflict(true);
main();
}
})
}
});
你的情況:
CFLoad.js("playlistcontent.jsonp");
[動態添加腳本標籤的
可能重複與SRC是可能包括document.write](http://stackoverflow.c om/questions/13121948/dynamic-add-script-tag-with-src-that-may-include-document-write) – bfavaretto 2013-02-15 19:53:29