contenescript.js
var someText = 'some text to show1';
chrome.extension.sendRequest({'action' : 'openMyTab','text': someText});
background.html
function onRequest(request, sender, callback) {
if (request.action == 'openMyTab') {
alert(" Inside onRequest with " + request.text);
}
};
chrome.extension.onRequest.addListener(onRequest);
这很好用。正如预期的那样,会发出警告信息。
但是将 contentscript.js 更改为类似的内容。
Wordlistonilne.Selector.dblClick = function(){
var st = Wordlistonilne.Selector.getSelected();
if(st!=''){
myMethod('openMyTab',st);
}
}
function myMethod(action,message){
alert("myMethod : action = " + action + "message = " + message);
chrome.extension.sendRequest({'action' : action,'text': message});
}
$(document).ready(function(){
$(document).bind("dblclick", Wordlistonilne.Selector.dblClick);
});
我通过操作和消息获得警报。但是chrome.extension.sendRequest似乎没有用。
F1 F1请帮帮我