Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

How do I add a Google Images search to my site?

You seem to be the wizard of unwrapping searches on sites and showing how to add them on our own Web sites, which is awesome. I saw - and really liked - your article on how to add a Google search box to my site but instead of searching Google, I want to search Google Images. Doable?


Dave's Answer:

Sheesh, I feel typecast, like some Hollywood character actor who invariably plays the heavy in the mob crime films or the dorky computer guy or something. :-)

The problem must be that I actually like to unwrap HTML code and figure out how to add neat search boxes to Web sites. I'm sure there's an entry in the DSM IV on the strange, pathological enjoyment of reverse engineering popular Web sites!

Anyway, okay. So. Google Images.

Let's start by cracking the page and seeing what's inside...

No. Let's not. Let's do this differently. This time, let's just look at the URL generated by a search and unwrap that directly. if I search for "banana", here's the URL generated:

http://images.google.com/images?hl=en&q=banana&btnG=Search+Images&gbv=2

Most of that can be axed, as Google includes information on the browser you're running, language you're using, etc., but they aren't critical for the search to succeed.

Trim it down to the bare essentials and it looks like this:

http://images.google.com/images?q=banana&btnG=Search+Images

Actually, a wee bit of testing reveals that the button value (btnG) can be omitted too, which means that in fact the URL is simply:

http://images.google.com/images?q=banana

That's sure nice and simple!

Now, to generate that URL, you need to use a GET form and the input field needs to be named "q" to match the Google specs. This can be easily done thusly:

<form method="get" action="http://images.google.com/images">
<input type="text" name="q" />
<input type="submit" value="Search Google Images" />
</form>

That's all you need for a basic Google Images search. Here, try it:

Simple enough! Now, I slipped one more thing in, adding target="_blank" as an additional attribute to the "form" tag so that the results would open in a different window. If you don't want that behavior, simply use the code as shown above.

Hope that gets you going with your own personal Google Images search feature.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

Dave, you're awesome! How could I encrypt the Google Image search so that the results would across even behind a firewall or content filtering tool?

With appreciation,
Miguel Guhlin

Posted by: Miguel Guhlin at March 27, 2008 5:00 PM

Thanks for this insight information!

Posted by: Bobbink at March 29, 2008 8:13 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]