Industry guru Dave Taylor offers free tech support on a wide variety of technical and business topics, including HTML, Apple iPhone, online advertising, Cascading Style Sheets, Web design, management, Unix, Linux, search engine optimization, online dating, Mac OS X, shell script programming and Microsoft Windows.

How do I add a Yahoo search box to my site?

How do I add a Yahoo search box on my site? I can see you've written about Google, but Yahoo's impossible to decipher!


Dave's Answer:

I agree with you about how complex Yahoo's search code is. In fact, I think that deciphering the Yahoo home page source code could easily be the final exam of a graduate level computer science course. It's really unbelievably baffling!

Fortunately you can reverse engineer the search by simply looking at the URL that is produced when you do a Yahoo search, strip out the unnecessary variables, and then build a rudimentary HTML form that produces the remaining. Let me show you...

I'll do a Yahoo search for Microsoft Zune and here's the URL that's produced:

http://search.yahoo.com/search?p=microsoft+zune&fr=yfp-t-501&toggle=1&cop=mss&ei=UTF-8

Now, within the Web browser's Address box, I'm going to experimentally remove specific name=value pairs to pare it down to the bare minimum. Turns out that the following much simpler URL produces the exact same search result:

http://search.yahoo.com/search?p=microsoft+zune

Nice! You can avoid all the other mumbo-jumbo, and thank goodness.

The form that produces that search looks like this:

<form method="get" action="http://search.yahoo.com/search">
<input type="text" name="p" />
&nbsp; <input type="submit" value="Search Yahoo!" />
</form>

That's all there is to it. Here's a Yahoo search box that has exactly that code underneath it:

 

One more tweak, though, just because that search box looks just a wee bit boring! You can drop in some minimal CSS and put a nice little box around the search form:

<form method="get" action="http://search.yahoo.com/search"
style="border:3px double black;padding:5px;">
<input type="text" name="p" />
&nbsp; <input type="submit" value="Search Yahoo!" />
</form>

Which now looks like this:

 

Hopefully that'll help you out!



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

Subscribe!

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

Comments

Using the above code worked fine but is it possible to have the search results open in a new page or tab(IE7)instead of navigating away from my website
Thank's
Dave

Posted by: Dave at February 11, 2008 1:57 PM

Dave, just add "target=_blank" within the FORM tag in the code above and you should have the behavior you seek.

Posted by: Dave Taylor at February 11, 2008 3:16 PM

Hi,

I am adapting the code to work with an affiliate programme. Problem is that I need to add other parameters to the URL.

Using your yahoo example it would be like I need the end URL to be:

http://search.yahoo.com/search?fr=yfp-t-501&p=microsoft+zune

I have tried making the action URL http://search.yahoo.com/search?fr=yfp-t-501&

But it strips off everything after the ? before adding the search term.

Posted by: Liz at February 20, 2008 7:42 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.









Uniblue: Free Virus Scan

Follow me on Twitter @DaveTaylor

Search
Find just the answers you seek from among our 2300+ 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
Book Links
© 2002 - 2009 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]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.