Google CSE在新窗口中打开

Rya*_*ant 9 html xhtml

我想将Google搜索栏集成到我的网站中,并使用Google CSE的默认代码,我有:

        <div id="cse-search-form" style="width: 100%;">Loading</div>
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript"> 
  google.load('search', '1', {language : 'en'});
  google.setOnLoadCallback(function() {
    var customSearchOptions = {};

    var imageSearchOptions = {};
    imageSearchOptions['layout'] = google.search.ImageSearch.LAYOUT_POPUP;
    customSearchOptions['enableImageSearch'] = true;
    customSearchOptions['imageSearchOptions'] = imageSearchOptions;

    var customSearchControl = new google.search.CustomSearchControl(
      '003243520079760326318:WMX-1462312306', customSearchOptions);

    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    var options = new google.search.DrawOptions();
    options.setSearchFormRoot('cse-search-form');
    options.setAutoComplete(true);
    customSearchControl.draw('shop.htm/cse', options);
  }, true);
Run Code Online (Sandbox Code Playgroud)

其次是风格和 </div>

但我不希望结果在同一页面上打开,我希望它们在searchresults.htm中打开,其中包含容器div

<div id="cse" style="width:100%;"></div> 
Run Code Online (Sandbox Code Playgroud)

如果我加入这种形式:

<form action="http://www.amberantiques.com/searchresults.htm" id="cse-search-box">
    <fieldset style="border:none;">
        <input type="hidden" name="cx" value="003243520079760326318:WMX-1462312306" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="31" />
        <input type="submit" name="sa" value="Search" />
    </fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)

然后表单将其发送到页面但不运行搜索,但如果您然后使用页面上的Google栏,则运行搜索正常.

基本上,你如何让谷歌栏打开结果页面?

干杯

And*_*les 15

如果您升级到最新的Google Code V2,则可以通过编辑粘贴的代码来显示结果.

<gcse:search></gcse:search>
Run Code Online (Sandbox Code Playgroud)

将此更改为

<gcse:search linktarget="_parent"></gcse:search>
Run Code Online (Sandbox Code Playgroud)


Tim*_*Tim 5

在为Google CSE构建代码时,“外观”选项之一是“两页”-允许您在一页上进行搜索,而在另一页上显示结果。 在此处输入图片说明


Saj*_*ood 5

你可以通过这个代码进行测试吗?

options.enableSearchboxOnly("http://www.amberantiques.com/searchresults.htm");
Run Code Online (Sandbox Code Playgroud)

这条线之间

var options = new google.search.DrawOptions();
Run Code Online (Sandbox Code Playgroud)

这条线

options.setSearchFormRoot('cse-search-form');
Run Code Online (Sandbox Code Playgroud)

然后将以下代码放在searchresults.htm中

<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
    function parseQueryFromUrl() {
    var queryParamName = "q";
    var search = window.location.search.substr(1);
    var parts = search.split('&');
    for (var i = 0; i < parts.length; i++) {
        var keyvaluepair = parts[i].split('=');
        if (decodeURIComponent(keyvaluepair[0]) == queryParamName) {
            return decodeURIComponent(keyvaluepair[1].replace(/\+/g, ' '));
        }
    }
    return '';
}

google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function () {
    var customSearchControl = new google.search.CustomSearchControl(
  '003243520079760326318:WMX-1462312306', customSearchOptions);

    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.draw('cse');
    var queryFromUrl = parseQueryFromUrl();
    if (queryFromUrl) {
        customSearchControl.execute(queryFromUrl);
    }
}, true);
</script>
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,您只需阅读谷歌提供的文档.您可以在"使用控制面板设计外观"部分中获得所需的信息.或者您可以在使用XML设计外观和部分中找到它.我想你正在寻找两个页面布局.

另一种选择是访问http://www.google.com/cse/manage/all,然后使用其中的控制面板根据需要自定义搜索引擎.