Skip to content Skip to sidebar Skip to footer

Multiple Google Cse (custom Search Engine) Boxes On Same Page

I am trying to implement two (different) Google CSE search boxes on the same page. The issue is that only the first instance works properly. For example, a sitewide search box in t

Solution 1:

From: http://www.google.com/cse/docs/cref.html

The parameter in /coop/cse/brand named "form" outputs the first getElementById in the code. As such, using http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en will create a cse-search-box-targetted code, whilst giving it box2 will trigger on a different ID. The keyword searchbox_demo is reserved.

Give it a go if you'd like to: http://jsfiddle.net/JTV6f/1/ . Considering what you are doing, however, if I were you, I'd switch to either the V1 or V2 APIs.

Solution 2:

This is a tested solution. Took me a while but I'm slow and I don't use CSS all the time.

Use the V1 code. When you select Get Code on the setup screen there is an option for the V1 code.

Put your search code in a div

div tag

searchcode

end div tag

Make your cse variables unique. That will be two places at the top of the code.

div id='cse'

and a little lower

customSearchControl.draw('cse', options);

For each search these should be the same but different than the other searches. I used cse0, cse1, cse2.

This will fix the searches so each search will work as specified but they will still share the same CSS.

So scope your styles with the scoped attribute.

style type='text/css' scoped

Do this for each search code. Now your searches can have their own look and feel, color, etc.

http://deltaboogie.com/search

Thanks, Hairy Larry

Post a Comment for "Multiple Google Cse (custom Search Engine) Boxes On Same Page"