我的Chrome“搜索扩展程序”有一个关键字,我想用用户的输入来触发搜索查询 . 在我的扩展程序的清单文件中,我声明了:
"omnibox": { "keyword" : "i" },
当我在多功能框中键入'i'并点击TAB / SPACE时,我看到我的扩展名生效了...但是,当我输入搜索查询并按ENTER(或选择建议的命令)时,没有任何反应 .
以下是我使用的示例,可在Google Code> Omnibox中找到:
// This event is fired each time the user updates the text in the omnibox,
// as long as the extension's keyword mode is still active.
chrome.omnibox.onInputEntered.addListener(function(text) {
var serviceCall2 = 'http://www.google.com/search?q=' + text;
});
// This event is fired with the user accepts the input in the omnibox.
chrome.omnibox.onInputEntered.addListener(function(text) {
chrome.windows.create({"url": serviceCall2});
});
是否有其他代码我缺少或上面的代码错了?
1 回答
每次文本更改时触发的正确事件是
chrome.omnibox.onInputChanged
您的代码无论如何都无法工作,因为
serviceCall2
是第一个消息监听器的本地代码 . 它在第二个中是未定义的 .您不需要两个侦听器,这应该工作: