代码:
简化后的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中加载了它,并修复了我发现的所有错别字和语法错误(以前是使用&
而不是&
),浏览器可以显示和解析它,但是它仍然无法作为搜索引擎加载。
可能FF不支持本地主机吗?我对此一无所知。
提前感谢您的任何见解!
window.external.AddSearchProvider
中使用数据URI吗? - Jason Nichols