Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


Can I have a Twitter search box / button on my site?

I think that Twitter is pretty darn cool and would really like to be able to add a Twitter search box to my web site. In fact, I'd love to have some buttons that are pre-defined searches, like for the name of the latest movie in the theater or a celebrity too. Are those possible? I haven't seen anyone do anything like that before...


Dave's Answer:

Everything's doable! The question is "how much of a nightmare would it be to add this?" and the good news is that the Twitter search system is incredibly easy to work with, and, better, it also has a sophisticated search engine so you can refine those buttons to filter out false matches (imagine the tons of false hits you'd get from the movie "Push", for example).

It all starts with search.twitter.com and a bit of HTML knowledge.

What we'll do is grab the URL from a search for those buttons, then reverse engineer the code needed to make their search box work and create an HTML code snippet that'll offer the same functionality. Ready?

First off, go to search.twitter.com and search for "Avatar" as a test. You'll end up with a Web page address (URL) like this:

http://search.twitter.com/search?q=Avatar

That's really all you need to create a rudimentary button: just use a graphic or text link and have that as the link. For example:

  Avatar buzz on Twitter

Easy, eh? The source to that:

<a href="http://search.twitter.com/search?q=Avatar">Avatar buzz on Twitter</a>

Without a detailed explanation, I'll say that any time you see a URL of this type, you can also unwrap it and make it into a simple HTML form too:

<form method="get" action="http://search.twitter.com/search">
<input type="hidden" name="q" value="Avatar" />
<input type="submit" value="Avatar buzz on Twitter" /></form>

When we actually include this code, we get this:
 

Cool, yes?

Now, let's turn that into a search box. It's quite easy, actually, and the code looks almost identical:

<form method="get" action="http://search.twitter.com/search">
<input type="text" name="q" />
<input type="submit" value="search Twitter" /></form>

Well, let's add a prompt to it so you know what you're typing in and move things around just a bit:

<form method="get" action="http://search.twitter.com/search">
Search Twitter for: <input type="text" name="q" />
<input type="submit" value="go!" /></form>

Let's see how that looks:

Search Twitter for:

Nice, yes? From here you can tweak and fiddle to your heart's content, but between the different ways I show to unwrap the search.twitter.com URLs you should be able to set up just what you want on your page!


More Useful HTML, JavaScript and Web Site Programming Articles:
✔   How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔   Can I embed a Facebook search box on my blog site?
I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔   Can I use CSS for drop shadows on my blog?
I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔   How can I embed interactive photo panoramas on my site/blog?
I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔   How can I create a Twitter search URL shortcut?
I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  









Reader Comments To Date:

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, Dave, for all your helpful information by buying you a cup of coffee!
Rather amazingly, there are no comments on this article yet.

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











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 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. Further, 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. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.