舊文件

此處文件僅供參考,請自行考量時效性與適用程度,其他庫藏文件請參考文件頁面
我們亟需您的協助,進行共筆系統搬移、及文件整理工作,詳情請查閱參與我們

製作 MozSearch 搜尋模組

出自 MozTW Wiki

Firefox 2 uses a simplified form of the OpenSearch format for storing search plugins. A MozSearch search plugin is an XML file that describes the search engine, its URL, and the parameters that need to be passed to that URL.

Warning: MozSearch is non-standard and is intended for internal use within Mozilla projects only. It should only be used if your intention is to distribute the search plugin packaged in a Firefox extension, or if you are creating plugins meant to be shipped by default in a Firefox build. For creating search plugins for installation from the web, see 為 Firefox 建立 OpenSearch 搜尋模組

The plugin file

The MozSearch format is similar to the OpenSearch format. The only difference is the root element and XML namespace.

Example: searching Yahoo!

The following XML is the bundled Firefox 2 search plugin for searching using Yahoo!:

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Yahoo</ShortName>
<Description>Yahoo Search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,R0lGODlhEAAQAJECAP8AAAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0NogQuyBDEnEd2kHkfFWUamEzmpZSfmaIHPHrRguUm/fT+UwAAOw==</Image>
<Url type="application/x-suggestions+json" method="GET"
     template="http://ff.search.yahoo.com/gossip?output=fxjson&amp;command={searchTerms}" />
<Url type="text/html" method="GET" template="http://search.yahoo.com/search">
  <Param name="p" value="{searchTerms}"/>
  <Param name="ei" value="UTF-8"/>

  <MozParam name="fr" condition="pref" pref="yahoo-fr" />
</Url>
<SearchForm>http://search.yahoo.com/</SearchForm>
</SearchPlugin>

Let's say the user chooses to use the Yahoo! search engine plugin and enters "mozilla" in the search box and presses the enter key. Firefox will use the above search engine description to construct the following search URL:

http://search.yahoo.com/search?p=mozilla&ei=UTF-8&fr=moz2

If the user clicks the magnifying glass icon in the search bar, or chooses the Web Search option in the Tools menu when the search bar isn't visible, the browser will take them to http://search.yahoo.com/, the value of the <SearchForm> element.

Example: searching MDC

This plugin lets you easily search the Mozilla Developer Center web site.

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>MDC</ShortName>
<Description>Mozilla Developer Center search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAABGdBTUEAAK%2FINwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz%2F%2Fz8DJQAggJiQOe%2Ffv2fv7Oz8rays%2FN%2BVkfG%2FiYnJfyD%2F1%2BrVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw%2F8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi%2FG%2BQKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo%2BMXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia%2BCuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq%2FvLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg%2FkdypqCg4H8lUIACnQ%2FSOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD%2BaDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg%3D%3D</Image>
<Url type="text/html" method="GET" template="http://developer.mozilla.org/en/docs/Special:Search?search={searchTerms}"/>
<SearchForm>http://developer.mozilla.org/en/docs/Special:Search</SearchForm> 
</SearchPlugin>

Notice in this case that instead of using <Param> to define parameters to the search engine, they're simply embedded inside the template URL. This is actually the preferred way to do things when using GET as the method. <Param> should be used for POST.

See also

個人工具