开发者

Trouble with chrome.extension.sendRequest();

开发者 https://www.devze.com 2023-01-15 00:34 出处:网络
contenescript.js var someText = \'some text to show1\'; chrome.extension.sendRequest({\'action\' : \'openMyTab\',\'text\': someText});

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

精彩评论

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