【问题标题】:How to add google chrome omnibox-search support for your site?如何为您的网站添加 google chrome 多功能框搜索支持?
【发布时间】:2011-11-29 14:49:02
【问题描述】:

当我在 Google Chrome 多功能框中输入一些 URL 时,我在其中看到消息“Press TAB to search in $URL”。例如,有一些俄罗斯网站 habrahabr.ru 或 yandex.ru。当您按 TAB 时,您将能够在该站点中搜索,而不是在您的搜索引擎中。 如何使我的网站能够做到这一点?也许,我需要在我的网站页面中编写一些特殊的代码?

【问题讨论】:

  • 那么,如何告诉 Chrome 我的网站是搜索引擎?

标签: html google-chrome browser opensearch


【解决方案1】:

Chrome 通常通过用户偏好来处理这个问题。 (通过chrome://settings/searchEngines

但是,如果您想专门为您的用户实现此功能,则需要向您的网站添加 OSD(开放式搜索说明)。

Making usage of Google Chrome's OmniBox [TAB] Feature for/on personal website?

然后将此 XML 文件添加到站点的根目录,并在您的 <head> 标记中链接到它:

<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml" />

现在,您网页的访问者会自动将您网站的搜索信息放入 Chrome 的内部设置中,地址为 chrome://settings/searchEngines

OpenSearchDescription XML 格式示例

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Your website name (shorter = better)</ShortName>
<Description>
Description about your website search here
</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">your site favicon</Image>
<Url type="text/html" method="get" template="http://www.yoursite.com/search/?query={searchTerms}"/>
</OpenSearchDescription>

重要的部分是&lt;url&gt; 项目。 {searchTerms} 将替换为用户在多功能栏中搜索的内容。

这里是OpenSearch 的链接以获取更多信息。

【讨论】:

  • 请注意,与 Firefox 不同,Chrome 仅当您将其放在 您网站的根目录时才会发现您的打开搜索描述。
  • 有没有办法让“omnibox-search”与 firefox 一起使用?
  • 如何在目标站点上找到直接指向查询框的url? (例如在谷歌翻译中)
  • 回答谷歌翻译将此添加到您的搜索引擎:translate.google.com/?source=osdd#auto|auto|%s
  • chrome://settings/searchEngines 添加搜索引擎可以节省时间!谢谢!
【解决方案2】:

通过搜索建议实现多功能框支持

@element119 给出的答案非常完美,但这里有一个稍微调整的代码,以支持搜索建议以及 Mozilla 支持。

按照以下步骤为您的网站实施多功能框支持。

  1. 将以下代码另存为 search.xml
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <script/>
  <ShortName>Site Name</ShortName>
  <Description>Site Description (eg: Search sitename)</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Image width="16" height="16" type="image/x-icon">Favicon url</Image>
  <Url type="application/x-suggestions+json" method="GET" template="http://suggestqueries.google.com/complete/search?output=firefox&amp;q={searchTerms}" />
  <Url type="text/html" method="GET" template="http://yoursite.com/?s={searchTerms}" />
  <SearchForm>http://yoursite.com/</SearchForm>
</OpenSearchDescription>
  1. search.xml 上传到您网站的根目录。

  2. 将以下元标记添加到您网站的&lt;head&gt; 标记

<link rel="search" href="http://www.yoursite.com/search.xml" type="application/opensearchdescription+xml" title="You site name"/>

确保将域名网址替换为您的域名。

【讨论】:

  • &lt;SearchForm&gt; 还是&lt;moz:SearchForm&gt;?我似乎在 OpenSearch 文档中找不到SearchForm,我在网上找到的所有其他资源都在使用&lt;moz:SearchForm&gt;
猜你喜欢
  • 2012-02-23
  • 2014-04-12
  • 2012-11-29
  • 2020-03-19
  • 1970-01-01
  • 1970-01-01
  • 2011-03-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多