Html 如何为您的网站添加 google chrome 多功能框搜索支持?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7630144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add google chrome omnibox-search support for your site?
提问by Abzac
When I enter some of URLs in Google Chrome omnibox, I see message in it "Press TAB to search in $URL". For example, there are some russian sites habrahabr.ru or yandex.ru. When you press TAB you'll be able to search in that site, not in your search engine. How to make my site to be able for it? Maybe, I need to write some special code in my site pages?
当我在 Google Chrome 多功能框中输入一些 URL 时,我在其中看到消息“按 TAB 在 $URL 中搜索”。例如,有一些俄罗斯网站 habrahabr.ru 或 yandex.ru。当您按 TAB 时,您将能够在该站点中进行搜索,而不是在您的搜索引擎中进行搜索。如何让我的网站能够使用它?也许,我需要在我的网站页面中编写一些特殊的代码?
回答by element119
Chrome usually handles this through user preferences. (via chrome://settings/searchEngines
)
Chrome 通常通过用户偏好来处理这个问题。(通过chrome://settings/searchEngines
)
However, if you'd like to implement this specifically for your users, you need to add a OSD (Open Search Description) to your site.
但是,如果您想专门为您的用户实现此功能,则需要向您的站点添加 OSD(开放式搜索描述)。
Making usage of Google Chrome's OmniBox [TAB] Feature for/on personal website?
在个人网站上使用 Google Chrome 的 OmniBox [TAB] 功能?
You then add this XML file to the root of your site, and link to it in your <head>
tag:
然后将此 XML 文件添加到站点的根目录,并在<head>
标签中链接到它:
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml" />
Now, visitors to your page will automatically have your site's search information placed into Chrome's internal settings at chrome://settings/searchEngines
.
现在,您网页的访问者会自动将您网站的搜索信息放入 Chrome 的内部设置中chrome://settings/searchEngines
。
OpenSearchDescription XML Format Example
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>
The important part is the <url>
item. {searchTerms}
will be replaced with what the user searches for in the omnibar.
重要的部分是<url>
项目。 {searchTerms}
将替换为用户在多功能栏中搜索的内容。
Here's a link to OpenSearchfor more information.
这是OpenSearch的链接以获取更多信息。
回答by Shan Eapen Koshy
Implementing omnibox support with search suggestions
使用搜索建议实现多功能框支持
The answer given by @element119 works perfect but here is a slightly tweaked code to support search suggestions as well as Mozilla Support.
@element119 给出的答案完美无缺,但这里有一个稍微调整的代码,以支持搜索建议和 Mozilla 支持。
Follow the steps below to implement omni box support for your site.
按照以下步骤为您的网站实施多功能框支持。
- Save the following code as search.xml
- 将以下代码另存为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&q={searchTerms}" />
<Url type="text/html" method="GET" template="http://yoursite.com/?s={searchTerms}" />
<SearchForm>http://yoursite.com/</SearchForm>
</OpenSearchDescription>
Upload search.xmlto the root of your site.
Add the following meta tag to your site's
<head>
tag
将search.xml上传到您网站的根目录。
将以下元标记添加到您网站的
<head>
标记中
<link rel="search" href="http://www.yoursite.com/search.xml" type="application/opensearchdescription+xml" title="You site name"/>
Make sure to replace the domain urls with your domain.
确保将域 url 替换为您的域。