Search Bar On Browser_2

二、             OpenSearch标准(www.opensearch.org)

OpenSearch支持Mozilla Firefox 2.0以上版本及Internet Explorer 7.0.

 

Firefox 2 supports the OpenSearch description format for search plugins. Plugins that use the OpenSearch description syntax are compatible with IE 7 and Firefox. Because of this, they are the recommended format for use on the web.

 

Firefox also supports additional search capabilities not included in the OpenSearch description syntax, such as search suggestions and the SearchForm element. This article will focus on creating OpenSearch-compatible search plugins that support these additional Firefox-specific features.

 

OpenSearch description files can also be advertised as described in Autodiscovery of search plugins, and can be installed programmatically as described in Adding search engines from web pages.

 

开放式搜索描述文件,

参见http://developer.mozilla.org/en/docs/Creating_OpenSearch_plugins_for_Firefox

XML文件描述一个搜索引擎实际上是很简单的,按照下面基本的模版,斜体字部分需要用户根据用户特定搜索插件的需要自定义。

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>engineName</ShortName>
<Description>engineDescription</Description>
<InputEncoding>inputEncoding</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,imageData</Image>
<Url type="text/html" method="method" template="searchURL">
  <Param name="paramName1" value="paramName1"/>
  ...
  <Param name="paramNameN" value="paramValueN"/>
</Url>
<Url type="application/x-suggestions+json" template="suggestionURL"/>
<moz:SearchForm>searchFormURL</moz:SearchForm>
</OpenSearchDescription>

1

ShortName

搜索引擎的短名

 

2

Description

搜索引擎的简要描述

 

3

InputEncoding

对输入搜索引擎的数据进行编码

 

4

Image

基于64位编码16X16大小的搜索引擎标志图片。

 

5

URL

描述搜索使用的URL,方法取决于是否使用GETPOST请求来获取结果。模版显示了查询的基本URL

注意,IE7不支持POST请求。

你可以指定2URL形式:

type="text/html" is used to specify the URL for the actual search query itself.

type="application/x-suggestions+json" is used to specify the URL to use for fetching search suggestions.

 

任何一种形式的URL,都可以用于替代用户在搜索条中输入的搜索条件。其他支持的动态查询参数的描述见OpenSearch 1.1 parameters. 参见http://www.opensearch.org/Specifications/OpenSearch/1.1/Draft_3#OpenSearch_1.1_
parameters

 

怎样在一台服务器执行查询支持,详细的参见Supporting search suggestions in search plugins. http://developer.mozilla.org/en/docs/Supporting_search_suggestions_in_search_plugins

 

6

Param

参数需要和查询一起,形成一对如key/value ,当指定值的时候 ,可以将用户在搜索栏中输入的插入到搜索条件中

注意,IE7不支持此元素

 

7

SearchForm

URL通过插件的搜索打开网站中的搜索页面,这样为Firefox提供了一种直接访问网站的方法。

注意,这个元素为Firefox特定的,不是OpenSearch说明书中的一部分,我们在上面的例子中使用”moz:”作为XML命名空间前缀来保证其他用户代理不支持这个元素安全的忽略它。

 

8

Autodiscovery of search plugins

一个网站提供一个搜索引擎并宣传它,这样Firefox的用户很容易下载和安装此插件。为了支持自动发现,你只需简单地在网站页面增加一行<HEAD>部分:

<link rel="search" type="application/opensearchdescription+xml" 
title="searchTitle" href="pluginURL">

斜体字说明如下:

searchTitle

搜索的执行名称,比如”Search MDC” 或是”Yahoo!Search”。这个值对应于你插件文件的ShortName.

 

PluginURL

XML搜索插件的URL,任何浏览器都可以下载它。

如果你的网站提供多种搜索插件,你可以使他们支持自动发现。例如:

<link rel="search" type="application/opensearchdescription+xml" 
title="MySite: By Author" href="http://www.mysite.com/mysiteauthor.xml">
<link rel="search" type="application/opensearchdescription+xml" 
title="MySite: By Title" href="http://www.mysite.com/mysitetitle.xml">

这样,你的站点提供的插件不仅是作者搜索而且可以为单独实体的标题。

 

9

Troubleshooting Tips

http://developer.mozilla.org/en/docs/Creating_OpenSearch_plugins_for_Firefox#
Troubleshooting_Tips


8 Safari上的搜索栏

9 IE7.0上的搜索栏

10添加搜索插件

11

OscarXie.net

关注质量与体验——电子商务与自动化测试
http://www.cnblogs.com/oscarxie/

原文地址:https://www.cnblogs.com/oscarxie/p/588767.html