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

lzfw57am  于 2023-02-01  发布在  Go
关注(0)|答案(2)|浏览(145)

当我在谷歌浏览器的万能盒输入一些网址,我看到它的消息“按Tab键搜索$URL”。例如,有一些俄罗斯网站habrahabr.ru或yandex.ru。当你按Tab键,你就可以在该网站搜索,而不是在你的搜索引擎。如何使我的网站能够为它?也许,我需要写一些特殊的代码在我的网站页面?

72qzrwbm

72qzrwbm1#

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>

最重要的部分是<url>项。{searchTerms}将替换为用户在综合栏中搜索的内容。
下面是OpenSearch的链接,可了解更多信息。

gz5pxeao

gz5pxeao2#

使用搜索建议实现多功能框支持

@element119给出的答案很完美,但这里有一个稍微调整的代码,以支持搜索建议以及Mozilla支持。
按照以下步骤为您的站点实现omni box支持。
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上载到站点的根目录。
1.将以下 meta标记添加到站点的<head>标记中

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

确保用您的域替换域url。

相关问题