
How can I create a "search Google" button on my Web page?Thanks for all the help re: adding a Google search box to web site... BUT, what I really want to do is have a button that when clicked will submit a SPECIFIC querry to google from within my web page. I guess its the equivalent of replacing the querry box input mechanism with a predefined text string... how do I do that? or... maybe just being able to pass parameters to google search... is any of this possible? This is a fun question and one that's surprisingly easy to solve, believe it or not. The key idea is that what you want to do is actually run the search that you want and just copy and paste the resultant search page URL. In addition to working with Google, this will work with just about any Web site that has a search engine where the search results page URL embeds the search term itself (some sites with more sophisticated searches use what's called a "method=post" search, so it's quite a bit harder to reverse-engineer). So let's say that you want to have a link on your site that offers up a pre-defined search for "iphone case". The first step would be to go to Google.com and actually do that search. Now, the results in your browser include a complex URL in the browser address bar: ![]() Pull out the URL by clicking in the address bar, selecting everything there, and then using Edit -> Copy, grab it. Here's what I get: http://www.google.com/search?q=iphone+case&ie=utf-8&oe=utf-8&aq=t&
rls=org.mozilla:en-US:official&client=firefox-a Now it turns out that much of the information in the URL is unneeded and you can just use "?q=iphone+case" as the search key but let's say that, unlike me, you don't want to experiment and find that out. So instead you just use the entire long URL. To create a regular text link with this search results URL, just use the format of "<a href="url">clickable text</a>" with the URL you've copied from the Google results and the "clickable text" being the search term. Like this: <a href="http://www.google.com/search?q=iphone+case&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a">/a</a>
That'll look like this: Look for iphone case on Google. Done! Now, for bonus points, let's see how we can make that a nifty button instead. This is a bit more tricky because we need to send each variable as a separate value so for this I am going to lop off all the unneeded variables. The result is this simple form: <form method="get" action="http://www.google.com/search">
<input type="hidden" name="q" value="iphone case" /> <input type="submit" value="search for iPhone cases on Google" /> </form> and the results of this are: That's it. Hope this makes it clear how you can capture these sort fo searches. Remember, any site where the search results page URL includes the search term can be reengineered this way, too, not just Google.
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
CGI Scripts and Web Site Programming
(Article 8602)
Tagged: google, html, html forms, iphone cases, reverse engineering Previous: How do I get pictures off my Apple iPhone? Next: How do I unfriend / remove a friend on Facebook? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. Wow, this is more simple than I thought. lol. -Mike Posted by: Mike Huang at November 12, 2008 2:51 PMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
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!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|