|
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.
Categorized:
CGI Scripts and Web Site Programming
(Article 8602,
Written by Dave Taylor)
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!
Wow, this is more simple than I thought. lol. -Mike Posted by: Mike Huang at November 12, 2008 2:51 PMWow Thats easy.... What would I need to add to make it open in a new Window I Use Safari. Posted by: Jim Waugh at December 3, 2010 2:46 AMI have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |