当我在 Google Chrome 多功能框中输入一些 URL 时,我在其中看到消息“按 TAB 键在 $URL 中搜索”。例如,有一些俄罗斯网站 habrahabr.ru 或 yandex.ru。当您按 TAB 键时,您将能够在该站点中进行搜索,而不是在您的搜索引擎中进行搜索。 如何让我的网站能够做到呢?也许,我需要在我的站点页面中编写一些特殊代码?
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 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 的链接以获取更多信息。
@element119 给出的答案很完美,但这里有一个稍微调整的代码来支持搜索建议和 Mozilla 支持。
按照以下步骤为您的网站实施多功能框支持。
<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&q={searchTerms}" />
<Url type="text/html" method="GET" template="http://yoursite.com/?s={searchTerms}" />
<SearchForm>http://yoursite.com/</SearchForm>
</OpenSearchDescription>
上传search.xml到您网站的根目录。
将以下元标记添加到您网站的
<head>
标记<link rel="search" href="http://www.yoursite.com/search.xml" type="application/opensearchdescription+xml" title="You site name"/>
确保将域网址替换为您的域。
谷歌浏览器不再支持站点特定搜索的自动发现
@googlechrome 推特账号:
我们做到了,因此新的站点搜索快捷方式不再自动添加到 Chrome 搜索栏中。我们这样做是为了避免将人们可能没有使用的网站搜索建议弄得一团糟。
这个回复最初是在评论中提供的(信用Olivier Lalonde)但我重新发布它以便更容易找到(例如,当我最初寻找答案时我没有看到这个评论)。