2010-03-29 76 views

回答

3

我做到了像這樣:(假設你有background.html陣列富)

chrome.extension.getBackgroundPage().foo 

但很顯然,這僅適用於像東西popup.html等要從後臺獲取數據在content_script.js文件頁面,您需要使用:

chrome.extension.connect() 

的API文檔是here

+0

這個方法我試過,但似乎不起作用。 在我的background.html中,有一個數組LEN,在我的content_script.js中,我這樣寫: alert(chrome.extension.getBackgroundPage()。LEN.length); 但它不起作用。 :( – 2010-03-29 03:13:25

+0

嗯,嘗試使用開發工具檢查content_script.js,並查看在控制檯上鍵入chrome.extension.getBackgroundPage()時會發生什麼。 – perimosocordiae 2010-03-29 04:39:20

+0

有錯誤信息「Resource解釋爲文檔,但是以MIME類型傳輸應用程序/ x-javascript。「,而我無法弄清楚它...... :( – 2010-03-29 05:05:40