Free tech support / small logo


Add a YouTube search box to my site?

I want to add a YouTube search box to my Web site. Can it be done?


Dave's Answer:

Can it be done? Pshaw! Anything can be built or reverse engineered given the time and motivation!

There's no reason to think that Google's YouTube site is any different.

The question is: is it going to be an easy reverse engineering job or a tough one, and that can be quickly ascertained by simply having a peek at the YouTube home page:

youtube home page search box

As you can see, it's a rudimentary search box with the input field and a submit button. That's it.

Should be quite easy to reverse engineer it!

To start, we'll crack open the source code to the page and isolate the HTML for the search itself:

youtube search box source code html

Looks like a lot of code, but if we scrub all the non-essential code and replace the fancy, attractive button with a regular HTML "submit" button, we're left with the small HTML snippet:

<form action="http://www.youtube.com/results" method="get">
<input name="search_query" type="text">
<input type="submit">
</form>

That's it. Seriously. It's not pretty, but it's functional:

Now let's make it a bit nicer looking by adding a box around it. This can be most easily done with some CSS styling within a "div" container, like this:

<div style="border:2px dotted black;padding:7px;">
<form action="http://www.youtube.com/results" method="get">
<input name="search_query" type="text">
<input type="submit">
</form>
</div>

That gives us this:

What do you think? Want something a wee bit more fancy? How about adding a background color to the box, and a different background color to the (larger) text input field and, for good luck, a third color for the button itself:

<div style="border:2px dotted black;padding:7px;background-color:#cfc;">
<form action="http://www.youtube.com/results" method="get">
<b>Search YouTube for: </b>
<input name="search_query" type="text" style="background-color:#ccf;" size="45">
<input type="submit" style="background-color:#ffc;">
</form>
</div>

The result:

Search YouTube for:

You can tweak and fiddle from here as you'd like, but that'll get you the rudiments of a YouTube search box on your site and a direction to travel for a custom fit. Good luck!









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments

Great little trick, far neater way to integrate YouTube into sites!

Posted by: Steve at June 14, 2010 3:47 PM

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

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











Remember personal info?


Please note that I will never send you any unsolicited 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.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 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.