当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Google CSE dynamic search from one search box

问题描述:

Is it possible to have one Google CSE box on a single page and provide different results dependent on an form on that page.

For example the user checks an input checkbox "videos" and their search result will only provide URLs in example.com/videos/ vs if "audio" is checked it will only show results in example.com/audio/ etc.

It seems like I would have to edit the constructor "as_sitesearch" variable but I don't know of a way to do that on the fly with the JavaScript API.

This is what I have so far:

function onLoad() {

var options = {}

options[google.search.Search.RESTRICT_EXTENDED_ARGS] = {

'as_sitesearch': 'www.example.com/audio/'

};

//where CUSTOM_ID searches www.example.com/

var customSearchControl = new google.search.CustomSearchControl('CUSTOM_ID', options);

var drawOptions = new google.search.DrawOptions();

drawOptions.setSearchFormRoot('search-form');

customSearchControl.draw('results', drawOptions);

}

google.setOnLoadCallback(onLoad);

分享给朋友:
您可能感兴趣的文章:
随机阅读: