|
|
How can I add a Google search box to my Web site?Dave, I keep visiting sites and seeing these cool search boxes that let you either search their entire site or search the entire Google database, all without leaving that page! I want to have something like this and would appreciate your helping me figure out the code needed.
This is a question that's going to result in some HTML listings. You know that, so there's no reason to panic! First off, the good news. Google itself actually has a nice page offering you HTML code you can just cut and paste onto your own Web pages to produce the search box you seek, and some variants beside. Just check out Google Free. Instead of relying on the bright sparks at Google, though, let's go through the steps of building our own search box instead, so you'll be able to see how it works. Also, not to pick on Google because I think the world of those folk, but their HTML samples could be cleaned up a bit, usually, so I've also recast it as proper XHTML rather than somewhat sloppy HTML. Just don't tell Larry and Sergey, okay? The basic technique involved here is to be able to manipulate one of the variables handed to the Google search engine, a variable called sitesearch. Set it to a null value and you're searching the entire World Wide Web, but set it to a specific domain and it's constrained exactly as if you had typed in the Google special notation site:domain. In addition to that, you need an input field and a submit button. Put them all together and here's the minimalist Google search form that lets the user alternate between just your site (well, in this case just my site) or the entire Web: <form method="get" action="http://www.google.com/search"> <input type="text" name="q" size="31" maxlength="255" value="" /> <input type="submit" value="Google Search" /> <input type="radio" name="sitesearch" value="" /> The Web <input type="radio" name="sitesearch" value="askdavetaylor.com" checked /> Ask Dave Taylor<br /> </form>There are some additional tweaks we can apply to make it a bit more fancy, including changing the radio buttons to a single check box, and aligning things a bit more nicely using a table and some simple CSS: <form method="get" action="http://www.google.com/search"> <div style="border:1px solid black;padding:4px;width:20em;"> <table border="0" cellpadding="0"> <tr><td> <input type="text" name="q" size="25" maxlength="255" value="" /> <input type="submit" value="Google Search" /></td></tr> <tr><td align="center" style="font-size:75%"> <input type="checkbox" name="sitesearch" value="askdavetaylor.com" checked /> only search Ask Dave Taylor<br /> </td></tr></table> </div> </form>Here's how that renders when included on an HTML page: If you'd like to use this on your own site, simply change the occurrences of askdavetaylor.com as appropriate. Not too hard at all!
Related 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!
Categorized:
HTML, JavaScript and Web Site Programming
(Article 3802,
Written by Dave Taylor)
Tagged: Previous: Selling jewelry on eBay, does it need to be appraised? Next: Should students use Google for research? Reader Comments To Date: 817Alexander said, on November 2, 2011 4:06 AM:
I recently got sick and tired of all the constant changes on my Google homepage. I like a nearly blank page to start with when I start surfing, because every site is trying to distract you with nonsense mostly. Now Google is constantly putting up new suggestions to try this and that, so I created my own home page with the simple search box you provided and I modified the links down to three: web, images and maps. What a beautiful and relaxing page (with my own background image) and no clutter! Thank you thank you, you're a life saver. Courtney said, on November 2, 2011 7:57 AM:
I tried using this code and it looks fine in iweb but when I load it to the internet it's shows up as a hit counter that I used to have on the page. Any suggestions on how to fix? David Oriol said, on November 4, 2011 1:17 PM:
Thank very much for your info Tony McGurk said, on November 11, 2011 4:25 AM:
Hi Dave. Thanks for this tip on making a search box that ACTUALLY works well on Blogger. I have tried a number of different ones that didn't work or worked poorly. Sending the search for my site only to Google search is a fantastic way of doing it. Once again Thanks Heaps!!! Sara said, on November 21, 2011 5:14 AM:
Hey Dave! Thank you so much for this, it is awesome! I just wonder if you can make a search box that ONLY search on my website? With no check box or radio botton? Thank you, again! Paul O'Connor said, on November 21, 2011 8:06 AM:
Thanks Dave Jerry said, on November 22, 2011 6:34 PM:
is there any way i can put the code into my own search box i did?, if so please help Nizam Khan said, on November 25, 2011 12:05 PM:
Awesome share ! suraj Vitekar said, on November 30, 2011 8:12 PM:
dude, :) Adakoo said, on December 1, 2011 9:33 PM:
i like it you post thank you very much Martyn James said, on December 9, 2011 9:28 AM:
Hi there Dave Atia said, on December 10, 2011 12:14 AM:
Hey! Dave I want that on clicking 'about me' the link directs the viewer to a page suggested by me.How could it be possible? Please reply me soon. Paul Hampton said, on December 12, 2011 7:49 AM:
Very helpful. I was getting a blank page because (I think) my site is using frames. I added the suggested line: target= "_blank" and all was good again. Tom said, on December 18, 2011 8:12 AM:
Hi Dave, Is there such a thing as a Latest Google Search Results Box that displays results for a pre-determined search string, i.e. U2? A new search would be done and the results refreshed whenever the page reloads and contain, say, 10 results. Thanks, Tom Richard said, on December 19, 2011 3:35 PM:
Is there a way to make it so that you do not need check box and that it will only search your site? Anirban said, on December 26, 2011 9:25 AM:
Hey Dave!!!! Thanks for the code. It really works.. surya said, on January 1, 2012 10:48 PM:
hi Dave, What i have done is: Martin said, on January 2, 2012 4:51 AM:
Hi Dave [form action="http://www.bellewaarde1915.co.uk/search/ksearch.cgi" method="get" name="search"] Every time I try and change things I mess it up so that it doesn’t work. srinivas said, on January 10, 2012 3:03 AM:
Hi, I Installed Google search in my website landing page , i want to display search result in searchresult.hmtl please send in detail Swati said, on January 12, 2012 6:18 AM:
Hi I was just juggling around with adding the google custom search + adsense code on my site and I found your post. Now, I tried both the adsense code and your code for search results and found that your code gives better results as compared to the adsense. Is there any way of combining yours and adsense code so that ads revenue is earned as well as I get better results on my search queries. Also, is adsense not giving good results because of its need to crawl the site thoroughly??? I have a new adsense account so I don't think it has crawled my site entirely. What's your advise? Thanks selvan said, on January 16, 2012 2:37 PM:
Hi and thanks. I've been trying all sorts of ways to do the below and can't, could you please help, thanks. The string below will search for The Beatles, as an example. I want a search box so the user only has to enter the artist they are searching for: anil said, on January 18, 2012 11:37 PM:
hi dave .. I embedded the site search code Egypt said, on January 20, 2012 9:38 AM:
The best way is to use Google Custom Search ! Chelsea said, on January 21, 2012 9:14 PM:
Hi Dave, First of all, thank you for your help. If you'll look at the Web site I've attached (still working on it), you'll be able to see the search bar I'm working with. It is part of the design so all I was trying to do was set it up to actually WORK and it does with your help, BUT since adding the value="iwarmbars.com" so it only does a site search, it actually adds those words over the design (I know, I know, this is purely superficial). Is there any way to make that hidden? Thanks in advance! chelsea said, on January 21, 2012 9:18 PM:
Additional note: If I do "input type=hidden" it removes the words AND the magnifying glass icon (still able to search). It's not crucial, I suppose, but I'd also like to have the magnifying glass icon. Is it possible that I will have to tinker around in the css and/or js files or is there a simple solution? Thanks again! Timothy benton said, on January 22, 2012 9:14 AM:
DAVE, Thanks. Tim Dave Taylor said, on January 22, 2012 3:17 PM:
Chelsea, it is indeed possible that you'll end up messing around with CSS. There's a CSS attribute called "crosshair", as described here: http://www.w3schools.com/cssref/pr_class_cursor.asp Tim, what you seek is really easy because the words "only search Ask Dave Taylor" isn't part of any form tag. So leave the <input> as is, but wrap the "only search..." element with something like this: <span style="color:green; font-weight:bold;">only search Ask Dave Taylor</span> Should be straightforward! Chelsea said, on January 24, 2012 9:05 AM:
Dave, I figured out an alternate solution of hiding both the magnifying glass icon and the words. Now my final problem is that it is not doing a full site search. I set the sitesearch to "iwarmbars.com" and it is only searching the index page, not additional pages connected to the site (/faq, /contact, /about, etc.). Did I miss something? Thanks again! Larry Woods said, on January 25, 2012 9:56 AM:
If I have a website named PetShopsInSanDiego.com, for instance, and when someone visited my site they would see a Google Search showing the Pet Shops only in San Diego without them typing anything into a Search Box; how would I do that? Dave Taylor said, on January 26, 2012 7:54 AM:
Larry, I don't really understand. If you're going to have a page that just shows search results, why wouldn't people just go to Google and get the results straight from the source? javi said, on January 30, 2012 3:22 PM:
Hi there, Dave, I used your google search box, with some modifications and noticed that the check box is on by default and when searching my page it cannot find pages with in my main page. Any suggestions? Cheers! Javi vaibhavdev said, on January 31, 2012 9:45 PM:
Sir is thier any way top get the reults in my web page only is their any way to migrate the results into my webpage Site is here:- Sir please help me as i am very much in need of this information............. Mantosh said, on February 1, 2012 8:50 AM:
Hi Dave, Dave said, on February 3, 2012 1:33 AM:
Hi, what I'd like is to add a specific phrase to searches. So if viewer types 'Washington' the search results are for 'Washington "Pet Supplies"'. Likewise, if the viewer types 'Boston', the results are for 'Boston "Pet Supplies"'. I'd be really grateful for any guidance on how to do this. Thanks Kieran said, on February 4, 2012 6:46 PM:
Hi, I've created acustom search engine in Google to look up websites that I want in it, I copied the code they gave me and put it onto a website called RM Platform, it worked for one area of the site, but I can't make it work in any other page. The code is as follows: Loading surya said, on February 10, 2012 8:57 AM:
When a user enters a query in my output screen it must be directed to the google search engine and only the "Searches related to" terms should be displayed to the user in turn.Please provide me the coding.It will be very much helpful if you provide it. Kumargaurav said, on February 10, 2012 11:14 PM:
Hi Dave....
Archit said, on February 15, 2012 6:22 AM:
Hey Dave,can you please tell me why 'name="q"'has been used as I have used this bar in my assignment ? Yogesh said, on February 22, 2012 3:23 AM:
Hi. The above information has been very useful for me. The only thing I am concerned with is --- Can i place an Image of magnify glass instead of search button. If so can anyone please help me with the same. Don said, on March 9, 2012 11:23 AM:
I purchased the google search engine, went through the setup steps, copied the code into my test page. Put it on my server and when I go to that page, it says "Loading" for a second, then nothing. When I view the source code the code they supplied is there, just nothing on the page. I looked at their "support forum" and almost nobody has posted in almost a month. And I was logged in, submitted my post. Saw it in that forum category, now I go back to make an edit, and my post is gone. Thanks Google. Almost no support and the simpliest test does zilch. Anyone have any ideas or links I can go to work through this? Thanks in advance, Sergey said, on March 15, 2012 7:44 AM:
Hi Don > Anyone have any ideas or links I can go to work through this? BTW there're other services that have better support and more interesting features. Like for example http://getwebsitesearch.com/ Babar hussain said, on March 19, 2012 9:45 AM:
Hi this is my 1st website Sean said, on March 20, 2012 10:48 AM:
Can I use this code on a subdirectory within my main domain? Or better yet can this code be used to only search a specific html page and not the whole domain? kkreiven said, on March 20, 2012 5:51 PM:
This is my version for mobile sites... <form method="get" action="http://www.google.com/m/search"> Dave Taylor said, on March 20, 2012 6:00 PM:
Nice job with that, KKreiven! Abdullah said, on March 21, 2012 7:04 AM:
thanx its grear to us this script its v simple and easy to use best wishes to script writer akshay said, on March 24, 2012 10:30 AM:
i want to search top t0 tweats with the keyword i enter on my website and the results should be display on my website..?? TP said, on April 1, 2012 2:48 PM:
Hi, I would like to add a search that only returns .co.uk sites. Is this possible please?? Thank you Dave Taylor said, on April 1, 2012 11:06 PM:
TP, yes. What you need to do is append " site:co.uk" to the end of the search pattern the user enters before you actually submit the search. I imagine the easiest way to do that would be to slip it into an OnClick event handler in the submit button. Good that phrase, you'll see examples of what I'm talking about. :-) ravi said, on April 12, 2012 5:36 AM:
Why should we only use name="q" for the text input, Dave Taylor said, on April 12, 2012 9:52 AM:
Ravi, it's because the program on the server that gets the search query is looking for 'q' as the name of the variable that contains the search word or term that you seek. Change it on the page and you also have to change the program to match. Maricelys said, on April 13, 2012 6:39 PM:
Thanks a lot!!! Ravi chandar said, on April 20, 2012 6:40 AM:
I want to add my company name in google autocompletion search box. how can i?? for example, my company name is 'fast ride calltaxi', i want this in the autocompletion google search if i type just fast.... Anum said, on April 21, 2012 12:29 PM:
hi, i put the following codes into my website, and i intend to let people search a product in my site only.. please let me know if the following codes are correct for that???? plz do reply me..i badly need your reply...
jsmb said, on April 25, 2012 4:58 AM:
Hello, very nice, thanks, But can i also use this on offline pages? For html pages on my harddisk? gaurav said, on April 26, 2012 10:41 AM:
i want to create a small search engine and wants to display the search result from the google or any other search engine into my search engine.... does anyone knows how to do that? Bholi said, on April 27, 2012 5:26 PM:
Thanks for providing the code to help us improve our Web site. It's through generous people like you that we've been able to avoid paying lots of money for programmers. Thanks! Charles Blundon said, on April 28, 2012 2:52 AM:
Dave, I really like your site. I have found that the way you present information is a lot easier to follow and use than other places. Thank you for the help! Zabi said, on May 2, 2012 12:57 AM:
Hello Dave, I have placed google search in my website, but its showing only index page when i type some keywords, Can you help me how to list more than 3 pages while search button is clicked, Please check this website (zeusmedcare.com) Manish Modgill said, on May 6, 2012 6:03 AM:
Hello Sir, Bill said, on May 7, 2012 3:36 PM:
Thanks man! This is helpful. nixonok said, on May 11, 2012 12:40 PM:
dude,you realy are good!thank you , Charles Kiyimba said, on May 17, 2012 1:46 PM:
Thanks a lot for this useful information. You deserve a thumbs-up. ganesh said, on May 26, 2012 12:18 AM:
HI, Dave I have cpy/pstd your code in my site, its working fine, but can I show the results in my own page like mydomain.com/results.html. Previously I was using a google code that had this option to show search results in desired page..
Stanley Straub said, on May 27, 2012 11:25 AM:
Hi Dave, Thanks, Daniel said, on June 1, 2012 2:00 PM:
Very help full. exactly what i was in search. thanks you David1979 said, on June 9, 2012 10:13 AM:
Hi, I am trying to integrate it into the search field of the following template but without any success! Here is the template: http://www.templatescreme.com/demo/fashion-magazine/104 The search field must not change! I like it the way it is! Also I like it to direct the visitor to a search page that looks similar in look and feel to my page Will appreciate your help. Thanks & Love Dave Taylor said, on June 14, 2012 9:00 AM:
Stanley and others who are finding that you see the *source code* to the search box, rather than the box itself in your web page editor, you need to enter the code when you're looking at the *code* to your existing page. Most of these web page editors have a "raw html" mode: that's what you need to use. Then it should work just fine. Good luck! Leta said, on June 15, 2012 3:07 PM:
Absolutely clean and beautiful. Thank you so much!!! Don't tell Google but yours is far superior. raju said, on June 15, 2012 11:56 PM:
i prepared code in html.i get the webpage how can use those web pages for creating website.please send me further process creating website. Daz said, on June 20, 2012 9:09 AM:
Hi Dave, great bit of code that works a treat. I've used the top code to add a search box to a new site I'm currently building but just wondered if it was possible to tweak the code to remove the radio buttons completely and for the search box to only show the text box and search button but nothing more and show results from my site only. Any help would be greatfully appreciated. Thanks once again for the code and for making my life much simpler. tumpa said, on June 22, 2012 12:16 AM:
good for learning John Onwuegbu said, on June 25, 2012 3:48 PM:
I had always preferred a native search box for my site to installing Google Search box. And the reason basically is that readers (especially the techies) tend to see Google search box as been a monetization scheme, so seldom uses it. Rashmi said, on July 5, 2012 11:40 PM:
This is a great article ! Thank you :) Rupam said, on July 7, 2012 1:09 AM:
Hi Dave, i have a question to ask... its related to google search but not serach box. I have developed a site for someone (an artist from CA). when she searches her site on google, on page 2 or 3 few search result comes up showing only the menu flash or the main flash (.swf) file but not any page. I found similer thing happens with other site also (i tried with yahoo, barbarabarry etc). my question is: is this normal? is there any security issue involved in such case? if so what i need to do to prevent this? I'm a designer turned developer and novish, not have much idea on SEO. Any idea/suggestion will be highly appeciated. Thanks a lot in adv. kiran khan said, on July 15, 2012 6:04 AM:
THIS IS A BEST WAY... Cendekiawan IT said, on July 26, 2012 7:44 PM:
i like this box for search... simple and powerfull... thank dave said, on August 7, 2012 10:39 AM:
hi dave what do i need to do if i want the results to appear on my site Many Thanks sunni and shia said, on August 14, 2012 3:08 AM:
Nice sample code for Adsense search box. JeHad Hussein said, on August 28, 2012 9:50 PM:
thnx for this box . it simple and nice, i will add to my blog. sahar said, on September 2, 2012 3:44 PM:
ur code is realy nice Gabriel Harper said, on September 30, 2012 2:27 PM:
You can also just add a search for Google+ only on your site: http://www.scriptalicious.com/blog/2011/08/add-google-plus-search-to-your-website/ Christian said, on October 2, 2012 7:22 AM:
Hi, I created a search box like yours, but I was wondering if there is any way I can make the search results to appears in my sime site instead of going to google? selina123abc1 said, on October 3, 2012 1:09 PM:
this is confusing Caleb said, on October 10, 2012 10:13 PM:
Thanks so much Dave, you just made my day! Mia Bee said, on October 18, 2012 11:14 AM:
When I add the coding it 1) creates a sort of "page break" between it and the rest of the site. And 2) trying to search only sends you to the home page, regardless of searching my site or the world wide web. Norma said, on October 20, 2012 6:41 AM:
Hi, I'm concerned about a search box created by my website designer. He says is a google search bar. It works, shows results from google and our website, but when you click on any of our website links, it does not work, it takes you to an ERROR PAGE NOT FOUND. jerry said, on October 26, 2012 5:44 AM:
thanks alot, at least now i can add a search box to my site. Rrapo said, on October 30, 2012 11:43 AM:
You are the best Dave! Razvan said, on November 1, 2012 6:42 AM:
Hello Dave! The tutorial is really nice and helpful, but it can be improved. I would like to know how can I integrate the search results page into my website. Ca you tell me? Thank you! Amy said, on November 14, 2012 2:59 AM:
Thanks Dave! nilkamal mandi said, on November 17, 2012 7:59 PM:
this html tag is quite good but i want a deferent one...this serch tag for google but i want a search tag that only shows the result of my personal site...please tell me GL said, on November 18, 2012 9:12 AM:
Dave, justin said, on November 29, 2012 10:48 AM:
is there a way to make the following code also show pictures on the search? justin said, on November 29, 2012 10:50 AM:
also, is there a way to make it so that you DO NOT have to check the site seach box... in other words, so that it automatically searches your site and NOT google? thank you, you are awesome Dave Taylor said, on November 29, 2012 10:58 AM:
Image inclusion is a function of the results Google finds. If it's a search of just your own site, I don't think it'll include images by default. And in terms of having it automatically just choose your own site, that's doable by turning the "type=checkbox" into "type=hidden" (which then lets you clean up the code a bit too: <input type="hidden" name="sitesearch" value="askdavetaylor.com" /> See what I mean? Easily done once you know how to tweak the HTML. Sarath baby said, on December 2, 2012 6:24 AM:
Like this you can also create a twitter search box within ur site! This is codded by myself. Its so easy if you know it! Abitha said, on December 12, 2012 5:36 AM:
its nice but i want to add a search box in my site it and i want it to search only within my site. i don't want it to search anything rather the info in my site. pls help me. Hi said, on December 17, 2012 12:03 PM:
Is there any way to point the search to my own PC, as well as the internet?
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help 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 Find Me on Google+ ADT on G+ |
Dave... Please man just put a simple code in your blog here for people who just want a simple code for just the search box and the button. Not much to ask huh? Thanks big guy appreciate it much.