没有方法getBackgroundPage

时间:2014-03-25 13:58:37

标签: javascript google-chrome-extension

我正在尝试了解Chrome扩展程序,我想我错过了一些东西。我想使用后台脚本上传文件......这是我的清单:

"manifest_version": 2,
"name": "myTest",
"description": "Upload file",
"version": "0.1",
"icons": {
    "64": "64.png",
    "16": "16.png",
    "32": "32.png",
    "128": "128.png"
},
"background":{
    "scripts": ["justupload.js"],
    "persistent": true
},
"content_scripts": [
    {
      "matches": ["http://my.url/page.html"],
      "js": ["link.js"]
    }
  ],
"permissions": [
    "http://my.url/page.html","background"
]

和link.js

function sendbg(){
var BGPage = chrome.extension.getBackgroundPage();
BGPage.senddata(document.getElementById('files'));
}
document.getElementById('files').addEventListener('change', sendbg, false);

文件更改时,我收到以下错误:

Uncaught TypeError: Object #<Object> has no method 'getBackgroundPage' 

由于

1 个答案:

答案 0 :(得分:0)

通过内容脚本进行通信需要通过消息解析来完成。 检查thisthis