0
我的要求是每当我单击应向内容脚本发送请求的扩展图标并且应该发送具有所需属性的回复时。我可以发送请求。而当我检查控制台内容脚本正在接收请求并处理它。但在弹出端我什么也收不到。
这里是内容脚本将popup.html加载到内容脚本的发送请求在此情况下不会收到任何内容
chrome.extension.onRequest.addListener(function ListeningMethod(request, sender, callback)
{
switch(request.action)
{
case "QuestionProperties":
sendResponse({attributes: {"h":"s","r":"t"} });
break;
}
});
而且在popup.html我将请求发送这样
$(document).ready(function(){
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {action: "QuestionProperties"}, function(response){
alert('received something'); // Even this is not alerting
var data = JSON.parse(response.attributes);
alert(JSON.stringify(data)); // Here also I could not recieve anything. At Contentscript side I have checked the response that is being sent. I am able to see the data. But at Popup side I am unable to recieve it. Please help me on this.
});
});
});
它就像一个魅力..谢谢你..非常感谢你。 – Exception 2012-01-05 19:00:53