Thursday, February 23, 2012

Query directly from your Browser's Omnibar/Addressbar

We need information and we want it fast. In the Internet age when every other service is online, getting to the right information quickly depends only on your computer, internet connection, browser, your bookmarks or your proficiency at formulating the right search queries. Fortunately todays Browsers have evolved. They are much contextual, intelligent and proactive. There is no longer a need of separate forms for the URL address and the search box. The hybrid of these two and more is the Omnibar.

But with the added feature of 'Key word custom search' like "Edit search engines" in Google Chrome, this Omnibar now becomes virtually, a 'command prompt' to the Internet, saweeet :)
As an example: Imagine: you need to find the current status of your train ticket. For this you would first search for the Railway's website, then you will have to scan the whole page and travel back and forth a few links to get to the final form where you can input your ticket number. now imagine how convenient it'd be if this whole process were to be reduced to one single step.

This is what I mean by the Command Prompt to the internet: Ideally you could come to this command prompt: the omnibar of your browser, and just type: "Ticket-Status xxxnnnxxx" and Voila!! your browser would take you to the final page of Railways website which shows the status of your ticket; all in but just one step.

and here's the great news this can be done and you don't really have to be a programmer to accomplish this.

Here's how:
When we browse the internet we access a URL. e.g.
When we search or query by clicking a button like 'Submit' after filling a form we also send that URL a bunch of variables/parameters.

there are two methods of sending information to a web server.

  1. Get: information is sent in plain text appended to the the Query String beginning with a Question Mark '?'
  2. Post: Most of the forms are submitted by this method. the Query string is sent in binary format and thus does not require appending of any text to any url.

So the idea is: If you know the right method - your information server is to be queried by, you could formulate the right 'request' that contains the information which you'd normally enter and then click, say 'submit', to get to the final information directly.

While all browsers support Direct Search,
Google Chrome lets you perform search queries only by Get method uptil v7.0.
Opera allows you to send requests by Post method also but unfortunately there is no way to pass more than one parameter.

Though there is a JavaScript hack to make use of multiple parameters in Get method, both in Chrome and Opera:
following line must be placed in the URL field of the "Add Seach engine" reference

javascript:url='lccp_pnrno1=%0s&lccp_pnrno2=%1s&submitpnr=Get+Status'; parts='%s'.split('qzq'); for(var i=0; i < parts.length; i++) url=url.replace(new RegExp('%'+i+'s', 'g'),parts[i]); location=url;

  • u may replace 'qzq' in the above with any thing that does not collide with the expected parameter values.
  • u may use an empty space ' ' instead of 'qzq' if you do not expect to have any space in any of the parameters.

    eg. keyword XqzqY =>

I have not been able to find out a similar solution for the 'Query String' viz the parameter list in Opera for Post method.

thus Here I present to you an ingenious solution:

  1. the Browser forwards your query to a local file;
  2. a JavaScript in this local file then converts the Get query into the required Post query and
  3. then forwards it to the final Search/Query engine.

the Catch is: you will have to do a little bit of digging to find out the specific variable: the form name and parameter list then customize the HTML re-director accordingly.

To identify the information being sent to the web server: the easiest method is to convert your form into type 'Get' from 'Post'. This way when you click 'Submit' your form you are likely to see your form name and parameter list along with corresponding values in plain text right in the address bar. (Unless its a AJAX form)

Add the following Bookmarklet:

Make sure that u can see the BookMarks bar.
if its not visible press Ctrl + G
Drag this bookmarklet to the Bookmarks bar Or Add a new BookMark with name: "Post2Get" & url: as the following:

javascript:(function(){var x,i; x = document.forms; for (i = 0; i < x.length; ++i) x[i].method="get"; alert("Changed " + x.length + " forms to use the GET method.  After submitting a form from this page, you should be able to bookmark the result."); })();

Download the following redirector XHTML file into ProgramFiles\Tools Folder

  1. SingleParam
  2. MultiParam
Edit the parameters according to your specific case:

Add an entry to this redirector file into the Browser
Right Click on the Omnibar
Edit search engines... > Add... > Name: [SERVICE_NAME] > Keyword: [SN] > URL: [file:///C:/Program%20Files/Tools/Redirect.html?query=%s] > OK

Go to the Query/Search Engines particular page that contains the particular query form.
Click on the Post2Get Bookmarklet
 It will then tell you how many forms it has converted from 'Post' to 'Get'
Now after filling in the form when you click on the submit button -

  • Case I: if the query works:
    u can directly use this URL for adding the search reference
  • Case II: if the query fails:
    u will still see the query string in the address bar, copy this

 identify the two parts of this string:

  1. static location of the URL
  2. identify the static variables and their values
  3. identify the dynamic variables

 Optionally and as a good practice you may add validation checking for these variables.
 Rename the redirector file to ur particular query
 copy this address to the Redirector HTML file and save

Now just type the Keyword in the omnibar <space> followed by the query term.

[Work in progress...]

No comments: