fcOnTheWeb Logo Web technologies, made easy.

fcOnTheWeb Red DotHow to add a Google search box to a web page

Adding a Google search box to your website is just about as easy it was to add YouTube videos to your website. After a little bit of digging around the Google site, we find that Google is giving away the code to add the search box to your site!

http://www.google.com/coop/cse/onthefly

This is the code Google gives us:

<!-- Use of this code assumes agreement with the Google Custom Search Terms of Service. -->

<!-- The terms of service are available at /coop/docs/cse/tos.html -->

<form name="cse" id="searchbox_demo" action="http://www.google.com/cse">

<input type="hidden" name="cref" value="" />

<input type="hidden" name="ie" value="utf-8" />

<input type="hidden" name="hl" value="" />

<input name="q" type="text" size="40" />

<input type="submit" name="sa" value="Search" />

</form>

<script type="text/javascript" src="http://www.google.com/cse/tools/onthefly?form=searchbox_demo&lang=">
</script>

And now adding the Google search bar to your web page is as easy as pasting that code in where you want it. The way it appears on the page is shown below:

Customising the search box (a little, within Google's guidelines - these guidelines, and these ones...) is easy too. What we are going to do is style the button to match the others on our site and change the text on the button.

To style the button, we simply add out predefined class: class="form_button". And to change the text we simply change the value attribute to be whatever we want. It looks like this:

<input type="submit" name="sa" value="Search with Google" class="form_button" />

So our implementation can be found on our search page, and looks like this:

The logo does not show in this box and the box does not actually work specifically to our site because Google's JavaScript does not work with more than one instance of the search bar on any one page. We can't edit the JavaScript, so there is not much that can be done about that. But as long as you do not have more than one instance on a page, it will be fine.

Google gets its search results from pages linked to by the page the search is on, as well as its cached results for that domain. So, the search on this article page in particular is inaccurate as it brings up a host of results from Google itself, due to the preceeding links to Google in the text. However, the one implemented on our Search page does a much better job of it.

To finish off, it is worth noting that Google provides a lot more options through its paid service, Google Site Search. These features allow you to keep the search results on your domain, add a custom header and style the results to match your theme - but it comes with a price.

ferrari_chris

Harua Ishaq (http://inyass4ishaq.gnbo.com.ng) says:

2012-08-10 09:01:46

adding of a google search page to mu web site

__________

Cheap Ralph Lauren UK (http://cheapralphlaurenuk.1minutesite.co.uk/) says:

2014-01-18 03:02:51

Gucci Shoes UK, http://www.guccivshoesfactory.net/
Polo Ralph Lauren Outlet Online, http://www.rralphlaurenoutlet.com/
Ralph Lauren Outlet Online, http://www.ralphlaurenipolo.com/
Ralph Lauren UK, http://www.polo-outletstoreonline.com/
Beats by Dre, http://www.discountbeatsbydresale.com/
Sacs Longchamp Pairs, http://www.saclongchamppairs.com/
Canada Goose Outlet, http://www.thecanadagooseoutlet.com/
Hollister UK Shops, http://www.cheaphollistersale.co.uk/
Michael Kors Outlet Online, http://www.michaelkors.so/
Marc Jacobs Outlet, http://www.marcjacobsonsale.com/
Michael Kors Outlet, http://www.michaelkorsr.com/
North Jackets Clearance, http://www.north-faceoutletonlines.net/
Burberry Outlet Online, http://www.burbagssale2013.com/
North Clearance Outlet Online, http://www.north-clearance.com/
Coach Factory, http://www.coach-factories.com/
Coach Outlet Online, http://www.coach-purseonsale.com/
Cheap Ralph Lauren UK, http://cheapralphlaurenuk.1minutesite.co.uk/
http://marcjacobsoutlet-2014.tripod.com/
http://www.michaelkorsoutletr.com/
Michael Kors Outlet
Discount Michael Kors
http://www.michael-korsfactorystore.com/
Michael Kors Outlet
Michael Kors Factory Store
http://www.michaellkorsfactoryonline.com/
Michael Kors Outlet
Discount micheal kors

__________

mbt usa (http://www.mbtiuk.com/) says:

2014-04-16 07:07:04

Mbt shoes are able to help you solve the problem of physical ache. When Legs and feet are twisted, when back and hips are ached, when joint and muscles or ligaments get hurt, mbt shoes are helpful to these pains\' recovery.


Add your comment on this article below:

Sorry, there's an error with your form entries. We really appreciate your comment, so please try again.

Form submitting now...

Name:

Website:

Email address (not displayed):

Enter your comment below: