我在网页中使用自定义 Google 搜索
代码:
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function(){
var customSearchControl = new google.search.CustomSearchControl('016457557644291857915:ivjbplcmt5k');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
}, true);
</script>
上面的代码工作正常,但它在该页面本身中显示搜索结果。我想在单独的页面中显示搜索结果页面。
需要代码帮助
最佳答案
您可以使用自定义搜索 API 中的特殊方法,只需在 setResultSetSize() 之后、draw() 方法之前添加此行:
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_BLANK)
链接将在新窗口中打开。
我希望它能如你所愿。
关于javascript - 如何在新页面中显示自定义谷歌搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1983944/