1

我需要准确地知道浏览器上的搜索框是如何工作的。我想在数学中用定制的搜索引擎替换搜索的东西,比如维基百科和谷歌。您可以在 iGoogle 中看到它们。所以:

如何将 Google CSE 添加到浏览器的搜索框中?

4

4 回答 4

6

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

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

这也应该适用于谷歌自定义搜索。

您必须创建一个特殊的 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>
于 2009-06-28T07:30:09.563 回答
2

浏览器搜索框是在一种称为 OpenSearch 的技术中实现的。见:http ://www.opensearch.org/ (网站目前关闭?)

Mozilla 有一个很好的页面,它解释了如何为他们的浏览器实现这一点:https ://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox 虽然那里有一些 Mozilla 特定的详细信息,但该页面可以作为交叉的一个很好的起点- 浏览器实现。

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

看看谷歌为他们支持的不同浏览器返回了什么:

* 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.
于 2009-07-10T13:49:30.277 回答
0

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

于 2009-06-28T05:33:52.840 回答
0

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

于 2009-06-28T06:00:25.313 回答