如何为您的网站添加 google chrome 多功能框搜索支持?
当我在 Google Chrome 多功能框中输入一些 URL 时,我在其中看到消息按 TAB 在 $URL 中搜索".例如,有一些俄罗斯网站 habrahabr.ru 或 yandex.ru.当您按 TAB 时,您将能够在该站点中进行搜索,而不是在您的搜索引擎中进行搜索.如何让我的网站能够使用它?也许,我需要在我的网站页面中编写一些特殊代码?
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?
Chrome 通常通过用户首选项来处理此问题.(通过 chrome://settings/searchEngines
)
Chrome usually handles this through user preferences. (via chrome://settings/searchEngines
)
但是,如果您想专门为您的用户实施此功能,则需要向您的网站添加 OSD(开放式搜索描述).
However, if you'd like to implement this specifically for your users, you need to add a OSD (Open Search Description) to your site.
然后将此 XML 文件添加到站点的根目录,并在 <head>
标签中链接到它:
You then add this XML file to the root of your site, and link to it in your <head>
tag:
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml" />
现在,您网页的访问者会自动将您网站的搜索信息放入 Chrome 的内部设置中,网址为 chrome://settings/searchEngines
.
Now, visitors to your page will automatically have your site's search information placed into Chrome's internal settings at 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>
重要的部分是
项.{searchTerms}
将替换为用户在多功能栏中搜索的内容.
The important part is the <url>
item. {searchTerms}
will be replaced with what the user searches for in the omnibar.
这里是 OpenSearch 的链接,了解更多信息.
Here's a link to OpenSearch for more information.