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

  

我怎么可以添加谷歌的CSE到   浏览器的搜索框?

有帮助吗?

解决方案

您可以创建所谓的“搜索服务”为您的网站。你应该有它接受搜索关键字作为查询字符串在您的网址,如

您网站上的搜索页面
  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>

其他提示

浏览器搜索框是用一种称为OpenSearch的技术来实现。参见:(?网站目前向下) http://www.opensearch.org/

Mozilla有一个良好的网页,其中介绍了如何实现此为他们的浏览器: https://开头开发商。 mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox 中虽然也有一些Mozilla的具体细节还有,该页面可以作为一个很好的起点,跨浏览器的实现。

添加自动完成搜索框是一个有点棘手。如由Mozilla描述的第一添加自动完成的查询网址。然后,你必须手艺服务器这符合什么不同的浏览器上期望的响应。

看看是谷歌返回他们所支持的不同的浏览器:

* 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.

这可能取决于浏览器到浏览器,但用Firefox,它是简单的定制:看到搜索栏以及如何轻松添加自定义搜索引擎在火狐浏览器搜索栏

微软提供了一个工具来添加自定义搜索提供商IE,并添加到搜索栏扩展可以做同样的Firefox浏览器。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top