如何为您的网站添加 google chrome 多功能框搜索支持?

问题描述 投票:0回答:3

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

html google-chrome browser opensearch
3个回答
220
投票

Chrome 通常通过用户偏好来处理这个问题。 (来自

chrome://settings/searchEngines

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

在个人网站上使用 Google Chrome 的 OmniBox [TAB] 功能?

然后您将此 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>

重要的部分是

<url>
项目。
{searchTerms}
将替换为用户在多功能栏中搜索的内容。

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


37
投票

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

@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. 将以下元标记添加到您网站的

    <head>
    标记

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

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


0
投票

谷歌浏览器不再支持站点特定搜索的自动发现

@googlechrome 推特账号:
我们做到了,因此新的站点搜索快捷方式不再自动添加到 Chrome 搜索栏中。我们这样做是为了避免将人们可能没有使用的网站搜索建议弄得一团糟。

这个回复最初是在评论中提供的(信用Olivier Lalonde)但我重新发布它以便更容易找到(例如,当我最初寻找答案时我没有看到这个评论)。

© www.soinside.com 2019 - 2024. All rights reserved.