我开发了一个 Firefox 插件,该插件在 Firefox 24 中无法使用。
我的插件根据一些用户设置将搜索引擎添加到搜索栏。为了添加搜索引擎,我使用 addEngine()来自nsIBrowserSearchService
。
直到Firefox 23,该功能还选择了添加的引擎,因此用户可以立即使用它。从 Firefox 24 开始,此行为停止:正在添加引擎,但不再选择引擎。
... the new engine will be used right away automatically.
我该怎么做才能强制在 Firefox 24 中立即使用新引擎?
最佳答案
一个小解决方法是在添加新搜索引擎后直接更改默认搜索引擎的首选项:
browser.search.defaultenginename
此首选项采用搜索引擎的确切名称。
此外,this MDN tutorial 中有有关添加搜索引擎的更多信息。 :
function startup(data, reason) {
firstRun = reason == ADDON_INSTALL;
// Re-select the search engine if this is the first run
// or we're being re-enabled.
selectSearch = firstRun || reason == ADDON_ENABLE;
// Only add the engine if it doesn't already exist.
if (!Services.search.getEngineByName(ENGINE_DETAILS.name)) {
Services.search.addEngineWithDetails.apply(Services.search,
["name", "iconURL", "alias", "description", "method", "url"].map(
function (k) ENGINE_DETAILS[k]))
}
let engine = Services.search.getEngineByName(ENGINE_DETAILS.name);
// If the engine is not hidden and this is the first run, move
// it to the first position in the engine list and select it
if (selectSearch && !engine.hidden) {
Services.search.moveEngine(engine, 0);
Services.search.currentEngine = engine;
}
}
关于Firefox:以编程方式添加搜索引擎并立即使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19171103/