浏览器如何做? 搜索框有用吗?

发布于 2024-07-25 20:01:40 字数 1571 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻梦旅人 2024-08-01 20:01:40

您可以为您的网站创建所谓的“搜索提供程序”。 您的网站上应该有一个搜索页面,它接受搜索关键字作为 URL 中的查询字符串,例如“

  http://www.example.com/search?q=meaning+of+life

这也应该适用于 Google 自定义搜索”。

您必须创建一个特殊的 XML 文件(例如,将其称为 SearchProvider.xml)并将其放在您的 Web 服务器上:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
   <ShortName>Example Search Provider</ShortName>
   <Description>Finds answers to the most important question of the universe</Description>
   <InputEncoding>UTF-8</InputEncoding>
   <Url type="text/html" template=" http://www.example.com/search?q={searchTerms}"/>
</OpenSearchDescription>

然后,您需要在页面的标题部分:

 <link title="Example Search Provider" rel="search"
     type="application/opensearchdescription+xml"
     href="http://www.example.com/SearchProvider.xml" />

您还可以插入指向页面的链接,该链接允许您的用户将搜索提供程序添加到浏览器:

<a href="#"
   onclick="javascript:window.external.AddSearchProvider('http://www.example.com/SearchProvider.xml');">
Example Search Provider</a>

You can create so called "Search Providers" for your sites. You should have a search page on your site which accepts the search keywords as query string in your URL, like

  http://www.example.com/search?q=meaning+of+life

This should work work Google Custom Search as well.

You'll have to create a special XML file (call it SearchProvider.xml, for example) and put it on your web server:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
   <ShortName>Example Search Provider</ShortName>
   <Description>Finds answers to the most important question of the universe</Description>
   <InputEncoding>UTF-8</InputEncoding>
   <Url type="text/html" template=" http://www.example.com/search?q={searchTerms}"/>
</OpenSearchDescription>

Then, you'll need to insert a special link tag in your page's header section:

 <link title="Example Search Provider" rel="search"
     type="application/opensearchdescription+xml"
     href="http://www.example.com/SearchProvider.xml" />

You could also insert a link to your page, which allows your users to add the search provider to the browser:

<a href="#"
   onclick="javascript:window.external.AddSearchProvider('http://www.example.com/SearchProvider.xml');">
Example Search Provider</a>
迷迭香的记忆 2024-08-01 20:01:40

浏览器搜索框是通过称为 OpenSearch 的技术实现的。 请参阅:http://www.opensearch.org/(网站目前已关闭?)

Mozilla 有一个很好的页面其中解释了如何为其浏览器实现此功能: https://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox< /a> 虽然其中有一些 Mozilla 特定的详细信息,但该页面可以作为跨浏览器实现的良好起点。

向搜索框添加自动完成功能有点棘手。 首先按照 Mozilla 的描述添加自动完成查询 URL。 然后,您必须在服务器上制作符合各种浏览器期望的响应。

看看 Google 针对其支持的不同浏览器返回的结果:

* Firefox: http://suggestqueries.google.com/complete/search?client=firefox&hl=en-US&q=xmarks
      o Content-Type: text/javascript
      o Response body: ["xmarks",["xmarksthaspot","xmarksthescot","foxmarks safari","xmark.com","gmarks firefox","x marks foxmarks","xmarksthespot","xmarks ie","foxmarks addon","foxmarks for ie"]] 
* Safari: http://suggestqueries.google.com/complete/search?client=safari&hl=en-US&q=xmarks
      o Content-Type: application/json
      o Response body: ["xmarks",[["xmarksthaspot","18,400 results","0"],["xmarksthescot","196,000 results","1"],["foxmarks safari","148,000 results","2s"],["xmark.com","336,000 results","3s"],["gmarks firefox","50,700 results","4s"],["x marks foxmarks","13,500 results","5s"],["xmarksthespot","20,500 results","6"],["xmarks ie","96,400 results","7"],["foxmarks addon","210,000 results","8s"],["foxmarks for ie","191,000 results","9s"]]]
* Others: http://suggestqueries.google.com/complete/search?client=ie&hl=en-US&q=xmarks
      o Content-Type: text/javascript
      o Response body: I'm not sure it's relevant. It's essentially the exact same format as Safari above, but it's wrapped by a JavaScript call to window.google.ac.h(). I'm not 100% certain, but that looks like the callback to their HTML-page version of auto-completion and suggests to me that they don't really support opensearch auto-completion in anything but Firefox and Safari.

Browser search boxes are implemented in a technology called OpenSearch. See: http://www.opensearch.org/ (site currently down?)

Mozilla has a good page which explains how to implement this for their browsers: https://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox While there are a few Mozilla-specific details there, that page can serve as a good starting point for cross-browser implementation.

Add auto-complete to the search box is a bit trickier. First add the auto-complete query URL as described by Mozilla. Then you must craft a response on your server which conforms to what the various browsers expect.

Take a look at what Google returns for the different browsers they support:

* Firefox: http://suggestqueries.google.com/complete/search?client=firefox&hl=en-US&q=xmarks
      o Content-Type: text/javascript
      o Response body: ["xmarks",["xmarksthaspot","xmarksthescot","foxmarks safari","xmark.com","gmarks firefox","x marks foxmarks","xmarksthespot","xmarks ie","foxmarks addon","foxmarks for ie"]] 
* Safari: http://suggestqueries.google.com/complete/search?client=safari&hl=en-US&q=xmarks
      o Content-Type: application/json
      o Response body: ["xmarks",[["xmarksthaspot","18,400 results","0"],["xmarksthescot","196,000 results","1"],["foxmarks safari","148,000 results","2s"],["xmark.com","336,000 results","3s"],["gmarks firefox","50,700 results","4s"],["x marks foxmarks","13,500 results","5s"],["xmarksthespot","20,500 results","6"],["xmarks ie","96,400 results","7"],["foxmarks addon","210,000 results","8s"],["foxmarks for ie","191,000 results","9s"]]]
* Others: http://suggestqueries.google.com/complete/search?client=ie&hl=en-US&q=xmarks
      o Content-Type: text/javascript
      o Response body: I'm not sure it's relevant. It's essentially the exact same format as Safari above, but it's wrapped by a JavaScript call to window.google.ac.h(). I'm not 100% certain, but that looks like the callback to their HTML-page version of auto-completion and suggests to me that they don't really support opensearch auto-completion in anything but Firefox and Safari.
依 靠 2024-08-01 20:01:40

它可能取决于浏览器,但对于 Firefox,自定义它很简单:请参阅搜索栏和如何轻松地将自定义搜索引擎添加到您的 Firefox 搜索栏。

It probably depends on the browser to browser, but with Firefox, it's simple to customize it: see Search Bar and How To Easily Add A Custom Search Engine To Your Firefox Search Bar.

萝莉病 2024-08-01 20:01:40

Microsoft 提供了一个向 IE 添加自定义搜索提供程序的工具,并且“添加到搜索栏”扩展允许您对 Firefox 执行相同的操作。

Microsoft provide a tool to add custom search providers to IE, and the Add to Search Bar extension allows you to do the same with Firefox.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文