开发者

Trouble with chrome.extension.sendRequest();

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);

This works fine. And as expected gives an alert message.

But on changing the contentscript.js to something like this.

Wordlistonilne.Selector.dblClick = function(){
  var st = Wordlistonilne.Selector.getSelected();
  if(st!=''){
 myMethod('openMyTab',st);
  }
}


function myMethod(action,message){
 alert("myMethod : action = " + action + "message = " + mess开发者_开发百科age);
 chrome.extension.sendRequest({'action' : action,'text': message});
}

$(document).ready(function(){
  $(document).bind("dblclick", Wordlistonilne.Selector.dblClick);
});

I get the alert with the action and message. But the chrome.extension.sendRequest doesnt seem to work.

F1 F1 please help me out

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜