As a member of the Google AJAX Search API Google Group I have seen multiple requests for a tutorial for non-developers who want to implement this on their site or blog. So, here goes.
Step 1: Get yourself an API key here.
Step 2: On your blog or website, add the following line in between the
< head>…< /head>
sections of your website:
(Note: If you are using a hosted wordpress account, you’ll have to add a page and then add the code since you do not have access to template code)
< script src="http://www.google.com/uds/api?file=uds.js&v=0.1&key=insert
your Google API Key" type="text/javascript">
(Note: Replace the text ‘insert your Google API Key’ with the API key provided to you by Google when you sign up)
Step 3: Add the following script (preferrably in the
< head>… < /head>
if you have access, but elsewhere will work) to your site:
< script language="Javascript" type="text/javascript">
//< ![CDATA[
function OnLoad() {
// Create a search control
var searchControl = new GSearchControl();
// add search controls in order you want them to appear
searchControl.addSearcher(new GblogSearch());
searchControl.addSearcher(new GwebSearch());
// add local search option
var localSearch = new GlocalSearch();
searchControl.addSearcher(localSearch);
// set starting point for local search
localSearch.setCenterPoint("Des Moines, IA");
// video search
searchControl.addSearcher(new GvideoSearch());
//set size of dataset you want returned
searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);
//search options
var searchOptions = new GsearcherOptions();
searchOptions.setExpandMode(GSearchControl.EXPAND_MODE_PARTIAL);
// draw options determine how results are displayed
var drawOptions = new GdrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
// Tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("searchcontrol"), drawOptions);
// Execute an inital search (optional - you can remove this line if you dont want it to auto search)
searchControl.execute("Get A New Browser");
}
window.onload = OnLoad;
//]]>
The above script can be modified to suit your needs. For example if you do not want to implement video search, simply remove the line
searchControl.addSearcher(new GvideoSearch());
from your script.
Step 3: Add a div in your template or page for the search control to access. In the case of the code above, you want to add
< div id="searchcontrol" />
to your markup. Put this where you want the search box and results to appear. Position it accordingly.
Step 4: Styling. Here is where you make the textbox, button, and results appear like you want them to. The easiest way to do this is to use Google’s stylesheet provided if you look through their samples deep enough. The easiest way is to paste the following code below the script code above:
< style type="text/css">
@import url(http://www.google.com/uds/css/gsearch.css);
< /style>
Now, if you want a custom style, you can download the linked stylesheet above and edit it. There are a lot of good comments in the stylesheet markup that will guide you through any customizations.
If you have any questions, leave us a comment here and we’ll get back to you to help you with what you need to get this up and running on your site.
Check out my first implementation here, and get a sneak peak at our new design.
Get more information using Google’s reference.
Or, join the Group.
tags: google, search, blog, ajax, javascript, web development
Note: I apologize for the code formatting — I am having issues with wordpress and the pre tags. So, html elements have an extra space in them so they render as text. Sorry for any inconvenience.
26 Responses
andy brudtkuhl » Blog Archive » links for 2006-06-05
June 5th, 2006 at 2:30 pm
1[...] Implementing Google AJAX Search As a member of the Google AJAX Search API Google Group I have seen multiple requests for a tutorial for non-developers who want to implement this on their site or blog. So, here goes. (tags: article howto google ajax search api tools web2.0 webdesign blog) [...]
The Web Design Blog
June 5th, 2006 at 2:33 pm
2[...] This is a simple tutorial for using the Google AJAX Search API on your website or blog. « Buttonator - create buttons via the web [...]
markl
June 5th, 2006 at 3:57 pm
3Hey,
Don’t instruct people to copy and edit gsearch.css. Instead, they should include it, and then add their own customizations after including gsearch.css.
aNieto2K » Blog Archive » Pon tu Google Ajax Search
June 5th, 2006 at 4:53 pm
4[...] Implementa Google Ajax Search en tu sitio de forma facil (Via Digg) [...]
Andy
June 6th, 2006 at 10:56 am
5I told them to include it in order to learn it. Once they have figured out which classes do what by playing with the stylesheet they can then create their own once they understand.
Implementare un motore di ricerca basato su google a ajax - sastgroup.com
June 8th, 2006 at 5:26 am
6[...] Continua a leggere su: http://getanewbrowser.com/2006/06/implementing-google-ajax-search/ Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages. [...]
Bitelia » dzone, el digg para desarrolladores
June 8th, 2006 at 5:58 am
7[...] Una de las noticias de portada que os destaco, es esta sobre un tutorial para el uso de la nueva interfaz de búsquedas en AJAX de Google. La he incorporado hace muy poco en mi blog personal (barra derecha, búsqueda) y salvo que no es compatible con Internet Explorer, es fantástica. [...]
Andy Brudtkuhl
June 8th, 2006 at 12:24 pm
8UDPATE: After helping a reader through a wordpress implementation we came upon something I failed to mention above. If you have custom wordpress implementation, you will want to put the <script> and <style> parts in the header.php file. And depending the section you want to put the control in, you will have to add the <div id=”searchcontrol”/> in there. The reader I helped decided to put this in the sidebar.php file.
Vinny Carpenter’s blog · Daily del.icio.us for Jun 08, 2006
June 8th, 2006 at 5:35 pm
9[...] Get A New Browser » Blog Archive » Implementing Google AJAX Search As a member of the Google AJAX Search API Google Group I have seen multiple requests for a tutorial for non-developers who want to implement this on their site or blog. So, here goes. (tags: ajax google API tools search webdesign web2.0 howto) [...]
Vinny Carpenter’s Link blog » Blog Archive » links for 2006-06-08
June 8th, 2006 at 5:47 pm
10[...] Get A New Browser » Blog Archive » Implementing Google AJAX Search As a member of the Google AJAX Search API Google Group I have seen multiple requests for a tutorial for non-developers who want to implement this on their site or blog. So, here goes. (tags: ajax google api tools search webdesign web2.0 howto) [...]
Implementing Google AJAX Search · Style Grind
June 8th, 2006 at 7:33 pm
11[...] GetANewBrowser as the scoop on implementing google’s lastest AJAX toy, its svelte new search box. [...]
Adnan Siddiqi
June 8th, 2006 at 11:06 pm
12Cool!!!
Amit Lamba
July 16th, 2006 at 6:41 pm
13Does this line: window.onload = OnLoad; avoid having to add this line in your html: ? Basically, they both do the same function, correct?
Amit Lamba
July 16th, 2006 at 6:43 pm
14Oops this comment form seems to have stripped part of my code i typed.
“ should be the same as window.onload = OnLoad();
Hopefully that doesn’t get stripped.
Andy Brudtkuhl
July 17th, 2006 at 9:25 am
15OnLoad is my custom onload function. It is equivalent to
window.onload = function() { //do stuff }also equivalent to another way I commonly call javascript on load:
window.onload = function init() { //do stuff }so_cute
September 2nd, 2006 at 9:31 pm
16I want to get a new blog
jason
October 10th, 2006 at 11:59 am
17nothing worse then a tutorial that doesn’t include a working example of the tutorial.
Andy Brudtkuhl
October 10th, 2006 at 1:17 pm
18Copy and Paste Jason. Works for me and everyone else that read it.
Nothing worse than a worthless negative comment.
Ken L
January 9th, 2007 at 5:44 am
19Interesting website, very informative and The above topic helpful. Good job
Seferm
April 21st, 2007 at 8:03 am
20Nice and simple tutorial
sanjay
October 18th, 2007 at 6:24 am
21this is needful, but i want to get only response links through the google search
WebTenet
December 6th, 2007 at 7:58 am
22Very useful article and nicely explained. Thank you very much.
esedic
March 7th, 2008 at 7:10 am
23Great tutorial!
Saved me some time.
Thanks!
mooniv
April 22nd, 2008 at 6:35 am
24I did my favourite search with google ajax here
Venkat
July 3rd, 2008 at 2:18 am
25hi i work the above sample but in design no control there how it will search
can u pls describe clearly.
Thanks
Halor
August 7th, 2008 at 12:26 pm
26You can find more information at http://www.ajaxatoms.com. Check in the article section.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Sponsors
Meta
Recent Readers
Sponsors
Categories
Reading
Links
Recent Entries
Recent Comments
Most Commented
Get A New Browser is proudly powered by WordPress - BloggingPro theme by: Design Disease
GANB is written by Andy Brudtkuhl of 48Web