【发布时间】:2014-09-24 21:06:07
【问题描述】:
背景故事:
我正在尝试根据用户输入的值为 Firefox 动态生成 OpenSearch 搜索插件,作为更大附加组件的一部分。我不包括围绕它的表单和杂乱无章,因为我已将其范围缩小为一个尝试导入任何 XML 的简单失败测试用例。
代码:
简体 JS
var browserSearchService = Components
.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var EngineProperties = {
xml : 'http://localhost/search.xml',
dataType: 3,
iconURL : 'http://localhost/logo.png',
confirm : false,
callback : function addEngineCallback(){
console.log('Jason is the greatest');
}
}
browserSearchService.addEngine( EngineProperties.xml,
EngineProperties.dataType,
EngineProperties.iconURL,
EngineProperties.confirm,
EngineProperties.callback);
实际的 XML
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Jason</ShortName>
<Description>Powered By Jason</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">http://localhost/logo.png</Image>
<URL method="get" type="text/html" template="http://search.mywebsearch.com/mywebsearch/GGmain.jhtml?ptb=100000487&ind=1406730191685&n=14787A74345&st=bar&searchfor={searchTerms}" />
<URL method="get" type="application/x-moz-keywordsearch"
template="http://search.mywebsearch.com/mywebsearch/GGmain.jhtml?&ptb=100000487&ind=1406730191685&n=14787A74345&st=bar&searchfor={searchTerms}" />
<Url method="get" type="application/x-suggestions+json"
template="http://ssmsp.ask.com/query?q={searchTerms}&li=ff&sstype=prefix"/>
<moz:SearchForm>http://search.mywebsearch.com/mywebsearch/GGmain.jhtml</moz:SearchForm>
</OpenSearchDescription>
(来自Mycroft Project)
从我所看到的错误应该表明一个无效的 XML 文件,但在我的一生中,我找不到任何问题。我已经将它加载到 Firefox 中,修复了我发现的所有拼写错误和语法错误(以前有 &amp; 而不是 &amp;,浏览器可以很好地显示和解析它,但它不会作为打开的搜索搜索加载引擎。
FF 不支持本地主机,也许吧?我在这里画一个空白。
提前感谢您的任何见解!
【问题讨论】:
标签: javascript xml firefox firefox-addon opensearch