代码之家  ›  专栏  ›  技术社区  ›  Rainer Plumer

使用“tab”进行搜索在googlecrome上(也许在其他浏览器上)是如何工作的[重复]

  •  0
  • Rainer Plumer  · 技术社区  · 7 年前

    当我在googlechromeomnibox中输入一些URL时,我看到其中的一条消息“Press TAB to search in$URL”。例如,有一些俄罗斯网站哈布拉哈布.ru或者yandex.ru公司. 当你按TAB键时,你可以在那个网站上搜索,而不是在你的搜索引擎上。

    0 回复  |  直到 13 年前
        1
  •  207
  •   Community Mohan Dere    8 年前

    Chrome通常通过用户偏好来处理这个问题。(通过 chrome://settings/searchEngines

    但是,如果您想专门为您的用户实现这一点,您需要向您的站点添加OSD(opensearch Description)。

    Making usage of Google Chrome's OmniBox [TAB] Feature for/on personal website?

    <head> 标签:

    <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml" />
    

    现在,你页面的访问者会自动将你网站的搜索信息放入Chrome的内部设置中 chrome://设置/搜索引擎

    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} 将替换为用户在omnibar中搜索的内容。

    这里有一个链接 OpenSearch 更多信息。

        2
  •  32
  •   Shan Eapen Koshy Kalle H. Väravas    10 年前

    @element119给出的答案非常完美,但这里有一个稍微调整的代码,支持搜索建议和Mozilla支持。

    按照以下步骤为您的站点实现omni-box支持。

    1. 将以下代码另存为 搜索.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. 上传 搜索.xml 到你网站的根目录。

    2. <head> 标签

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

    确保用您的域替换域URL。