Recent Comments

    Archives

    Chrome opensearch

    By kennydead 3 years agoNo Comments
    Home  /  Programming  /  Chrome opensearch

    Some time ago I stumbled upon a feature Google Chrome had. Well it was an accident actually since there is very little indication of it in the browser. Apparently, you can add a custom search engine to it, so that you can search only a specific websites using its build in search funcion (if it has one). Well this is all good but I managed to use it even on a site I never added. And this is what intrigued me the most.

    If you lets say try to visit youtube, when you type the website name in the URL bar, chrome lets you know, that if you press the Tab key you can directly search the website content without even visiting the site. If you try it, it should work. Well this is all good and true but I nevee added youtube’s search engine to Chrome… how does it work then? Well apparently, you can configure this for your own site so that your users can search in this way without adding it in the Chrome settings and it turns out it’s also preaty simple. This feature is called OpenSearch. Technicaly OpenSearch is a collection of technologies but that’s not important right now.

    To make this work on your website you need to insert on your page an OpenSearchDescriptor (OSD) which is essentialy an XML file with some properties that describe your search function, so that Chrome knows how to set up your custom search engine. Now to the actual setup you need to do:

    1. You need to add a line to your head tag in the HTML file of your root page on the site. You need to do this only on the root because that is the page a visitor will certainly visit. So add this line:

    <link rel="search" type="application/opensearchdescription+xml" title="your title" href="/opensearch.xml" />

    Here you are specifiing what would you like to do, a title and most importantly you tell the browser, where it can find your OSD. In this case in the file opensearch.xml. As you can guess, now we need to create this file. (Sidenote: the slash before the filename indicates that the file is in the root folder on the server. You can put it anywhere you like but then you must specify the correct path)

    2. Now you need to create the file mentioned above. Create a new file called “opensearch.xml” (if you called it that way) in the root folder (or in the location you specified ) and add the following xml code in it:

    <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
    <ShortName>Your website name (shorter = better)</ShortName>
    <Description>
    Description about your website search here
    </Description>
    <InputEncoding>UTF-8</InputEncoding>
    <Image width="16" height="16" type="image/x-icon">your site favicon</Image>
    <Url type="text/html" method="get" template="http://www.yoursite.com/search/?query={searchTerms}"/>
    </OpenSearchDescription>
    
    
    

    Here you need to change a few things if you want it to work. In the <ShortName> tag you put your website name. What you put here will be displayed in the green bar when you hit the Tab key. Add a description of your website in the <Description tag>, you can add an icon (even tho I don’t see it anywhere after I set this) and finaly and most importantly, for this to work you need to specify your search function URL. For example, the search url for my site would be:
    “http://markofornazaric.si/?s=”
    and after the URL just add “{searchTerms}” without quotes like in the example, so that Chrome knows that there should be the search parameter you input after you hit the Tab key.

    And that’s it. If you set it up correctly, the green omnibox feature of Chrome should work for you. It’s nothing revolutionary but it looks neat so that’s that :)

    One thing that i need to mention is that in order for this to work, a visitor must visit your root site at least once so that the browser saves the custom search engine.

    Categories:
      ProgrammingWeb
    this post was shared 0 times
     000
    About

     kennydead

      (3 articles)

    Leave a Reply

    Your email address will not be published.