我在下面的代码中将内容脚本中的数据传递给background.html,但由于某种原因它不适用于我..这里是代码..如何在Chrome扩展中的contentcript和background.html之间传递数据
Contentscript.js
var a1 ="Shan";
chrome.extension.sendRequest({method:"text",txt:a1}, function(response) {
d=response.data;
alert(d);
});
background.html
if(request.method == "text")
{
sendResponse({data:request.key});
}
else
{
sendResponse({data:request.key});
}
我的问题是,为什么我不能够通过变量 “A1” 到background.html?是否无法完成?
你是否按照文档? http://code.google.com/chrome/extensions/messaging.html您发布的代码似乎并不完整。如果这是你所有的,我建议再看看文档。 – 2012-02-10 17:22:35