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 does Google's "I'm Feeling Lucky" button work?

I think that Google's "I'm Feeling Lucky" button is great fun and want to have that feature on my site, but before I start digging into any sort of coding, can you tell me, how does it work?


Dave's Answer:

Before you tire out your brain too much, I should tell you that the "I'm Feeling Lucky" button is ridiculously simple: it takes you to the #1 match for the given search term or keyword. That's all. No randomization, no selection of one of the first ten, just the #1 match.

For example, let's say I searched on "diamond watch, mens" on Google (you can too: search). The results clearly show that the top match is the shopping comparison site Nextag:

Google Results: Diamond Watch, Mens

Now, go to the Google home page and again type in "diamond watch, mens", but this time, instead of clicking on "Search", click on "I'm Feeling Lucky".

Ahhhhh... now you know the secret!

To add an "I'm Feeling Lucky" feature to your own site is straightforward, albeit a bit tricky since Google makes it hard to read their Web pages because there's so much going on behind the scenes. In a nutshell, though, here's their home page search box:

<form action="http://www.google.com/search" name=f>
<input name=hl type=hidden value=en>
<input maxlength=2048 name=q size=55 title="Google Search" value="">
<input name=btnG type=submit value="Google Search">
<input name=btnI type=submit value="I'm Feeling Lucky">
</form>

We can simplify it a bit, but it turns out that if you just remove the "Google Search" button and only have "I'm Feeling Lucky", you get exactly the functionality you seek:

<form action="http://www.google.com/search">
<input name=q size=30 value="" />
<input name=btnI type=submit value="I'm Feeling Lucky" />
</form>

Here's how it looks in action:

It's not too complicated, really. You can change the label on the button by changing what's specified in the value= field, as you desire, and if you'd like to have the result show up on a new page, rather than replacing the current page, add target="_blank to the form tag as an attribute.



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

Doesn't work if you enter a search term and press the Enter key, you get normal search results page instead. :o(

Posted by: Sam at September 11, 2007 10:57 AM

Actually, Google's own example doesn't either...

http://www.google.com/help/features.html#lucky

2 x :o(

Posted by: Sam at September 11, 2007 11:00 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]