Abz*_*zac 140 html browser google-chrome opensearch
当我在Google Chrome多功能框中输入一些网址时,我会看到其中的消息"按TAB键搜索$ URL".例如,有一些俄罗斯网站habrahabr.ru或yandex.ru.当您按TAB键时,您将能够在该站点中搜索,而不是在搜索引擎中搜索.如何让我的网站能够做到这一点?也许,我需要在我的网站页面中写一些特殊代码?
ele*_*119 193
Chrome通常通过用户首选项处理此问题.(通过chrome://settings/searchEngines)
但是,如果您希望专门为用户实施此功能,则需要在站点中添加OSD(打开搜索说明).
在个人网站上使用谷歌Chrome的OmniBox [TAB]功能?
然后,将此XML文件添加到站点的根目录,并在<head>标记中链接到该文件:
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml" />
Run Code Online (Sandbox Code Playgroud)
现在,您网页的访问者会自动将您网站的搜索信息放入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>
Run Code Online (Sandbox Code Playgroud)
重要的部分是<url>项目. {searchTerms}将被用户在omnibar中搜索的内容替换.
以下是OpenSearch的链接以获取更多信息.
Sha*_*shy 28
@ 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>
Run Code Online (Sandbox Code Playgroud)
将search.xml上传到您网站的根目录.
将以下元标记添加到您网站的<head>标记中
<link rel="search" href="http://www.yoursite.com/search.xml" type="application/opensearchdescription+xml" title="You site name"/>
Run Code Online (Sandbox Code Playgroud)
请务必将域网址替换为您的域名.
| 归档时间: |
|
| 查看次数: |
38439 次 |
| 最近记录: |