Search code examples
javascriptgoogle-apiigoogle

How do I add the stock Google search to my own website **with auto-complete**?


I am not asking about Site Search. I am wondering how to include a Google search box that searches the whole internet (not limited to a single site like Site Search would be) that also uses the same autocomplete behavior you see on Google.com.

Some of you may remember iGoogle, which was Google's web portal which I used and loved for years until they shut it down last year. I'm making my own iGoogle replacement. I can easily enough add a textbox up top to do the search, but what I'm having trouble reproducing is the JavaScript autocomplete behavior that you get with regular Google.com.

So starting with this:

<form action="https://www.google.com/search" method="get">
<input type="text" name="q" value="" />
</form>

How do I get it to do auto-complete?


Solution

  • You will need to use some server side scripting and try to implement a solution based on suggested queries API. More can be found on this question

    On the client side try make an AJAx call as the user types to the textfield. As for the autocomplete functionality, I have used jQuery UI's plugin and it seems to work pretty great.