'chrome.extension.onRequest.addListener(function()'不运行其他功能

时间:2011-04-22 21:56:16

标签: javascript jquery google-chrome google-chrome-extension

我的功能“someFunc”通过单击按钮启动,但在接收请求时不启动。有什么想法吗?

var someVariable = 'someText';

function someFunc(message)
{
    alert(message);
}

$('#someBtn').click(function()
{
    someFunc(someVariable); //this run
    someFunc(); //this run
}   

chrome.extension.onRequest.addListener(function(request, sender, sendResponse)
{
    if (request.action == 'login_on')
    {
      alert(request.action); //this work
      someFunc(request.action); // this don`t run
    }
});

感谢。

2 个答案:

答案 0 :(得分:0)

警报经常搞砸了。例如,如果您尝试从弹出页面运行alert(),它将不会显示,但会停止执行更多代码。我建议您使用console.log替换提醒,看看是否有帮助。

答案 1 :(得分:0)

出于好奇,试试这个:

var someFunc = function(message){
    alert(message);
    return true;
}
顺便说一下,你的例子非常适合我。