Multiple Google CSE (Custom Search Engine) Boxes on Same Page

前端 未结 2 550
忘掉有多难
忘掉有多难 2021-01-20 06:50

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 b

相关标签:
2条回答
  • 2021-01-20 07:11

    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

    0 讨论(0)
  • 2021-01-20 07:15

    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.

    0 讨论(0)
提交回复
热议问题