tags:

views:

431

answers:

4

I need to precisely know how the search boxes on the browsers work. I would like to replace the search things, such as Wikipedia and Google, with customised search engines here at Mathematics. You can see them in iGoogle. So:

How can I add Google CSEs to the browsers' search boxes?

A: 

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.

eed3si9n
A: 

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.

Murali Suriar
+5  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/"&gt;
   <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}"/&gt;
</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');"&gt;
Example Search Provider</a>
splattne
I've done all of this, but it only seems to work in Firefox. The "<link..." part doesn't seem to do anything. The only time I can get it to work is when I click the link I created with the <a> tag...
cmcculloh
+2  A: 

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&amp;hl=en-US&amp;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&amp;hl=en-US&amp;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&amp;hl=en-US&amp;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.
pcorcoran