Search code examples
google-custom-search

How do browsers' Search boxes work?


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?


Solution

  • 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>