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

前端 未结 2 549
忘掉有多难
忘掉有多难 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

提交回复
热议问题