10

When you go to stackoverflow.com in Google Chrome and if you put a space infront of last character, the address bar changes to that in my screen shot below.

Then you can press Tab and you can type anything, and pressing enter will take you to the search page with your search term: https://stackoverflow.com/search?q=anything.

How can I do same thing for my site?

5

Assuming that you have a search feature on your site then you can take advantage of the OpenSearch functionality in Chrome.

Taken from the Chromium documentation:

To enable this for all users (even those who haven't used your search form):

On your site's homepage provide a link to an OpenSearch description document. The link to the OSDD is placed in the head of the html file. For example:

<head>
  <link type="application/opensearchdescription+xml"
        rel="search"
        href="url_of_osdd_file"/>
</head>

The important part of this document is the URL used to search your site.

The following is an example that contains the bare minimum needed, see the OpenSearch description document specification for the list of values you can specify.

<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
  <ShortName>Search My Site</ShortName>
  <Description>Search My Site</Description>
  <Url type="text/html" method="get"
       template="http://my_site/{searchTerms}"/>
</OpenSearchDescription>

When the user presses enter in the Omnibox the string {searchTerms} in the url is replaced with the string the user typed.

You can also include a suggestion service by adding another URL element with rel="suggestions" such as:

<Url type="application/json"
     rel="suggestions"
     template="http://my_site/suggest?q={searchTerms}"
     />

If you include this, the omnibox will use your suggestion service to provide query suggestions based on the user's partial query.

If your search box uses a GET request, then Chrome will enable this feature for uses who use it.

If you don't have a search page on your site then this won't work.

Props to Stephen for the initial link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.