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