由於您正在爲Chrome開發,我的確瞭解加載前內聯腳本的問題。 我寫這AJAX(jQuery的)片段,希望你會發現它有用:
$.ajax({
type: "GET", //or post?
url: "http://FOOBAR.COM", //change the url obviously..
datatype: "script", //identify the expected income
async: "true", //async is "true" by default, but let's make sure it's #t
success: function(result) {
/**now we append the script to the document, nothing too special,
just pay attention we inject it INSIDE the item and not as the src**/
var scr = document.createElement('script');
scr.innerHTML = result;
document.body.appendChild(scr)
},
error: function(result) {
//a simple error handling using the same method we used for the success
console.log(result)
var scr = document.createElement('script');
scr.innerHTML = "alert('ERROR!')";
document.body.appendChild(scr)
}
});
你今天引用添加到母版頁您的網站或只是popup.html頁? – HaBo
它只在popup.html頁面上。 – user2651403
java腳本文件有多大?如果這是小事,將它添加到你的主頁面? – HaBo