Javascript 谷歌CSE:结果页面在其他页面的div中?

Javascript 谷歌CSE:结果页面在其他页面的div中?,javascript,html,google-api,google-custom-search,Javascript,Html,Google Api,Google Custom Search,我想添加“Google CSE”,但我不想要Google创建的所有html和css,因此在互联网上,我几乎找到了解决方案: <!-- Google custom search box Start -by BloggerSentral.com --> <div class='cse' style='color:#000000;float:right;margin:6px 10px 0 0 ;'> <form action='http://www.google.com

我想添加“Google CSE”,但我不想要Google创建的所有html和css,因此在互联网上,我几乎找到了解决方案:

<!-- Google custom search box Start -by BloggerSentral.com -->
<div class='cse' style='color:#000000;float:right;margin:6px 10px 0 0 ;'>
 <form action='http://www.google.com/cse' target="_blank" id='cse-search-box'>
  <input name='cx' type='hidden' value='015736343358803935205:m2shzyx2lrg'/>
  <input type='text' name='q' size='35' />
  <input name='ie' type='hidden' value='ISO-8859-1'/>
  <input type="submit" name="sa" value="Search" />
 </form>
 <script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>
</div>
<!-- Google custom search box End -->

此代码必须插入到已存在的条形图中

在我的控制面板“google cse”中,在“布局”部分,我设置了“仅结果”选项

现在,当我在该栏中搜索时,它会打开一个页面:

id谷歌cse+关键字搜索

它是有效的

但是,我希望在我的网站页面的div(#content)中看到这些结果。这可能吗?

孩子们,我做到了!;) 我真的希望这个提议对很多人都有用,因为我注意到关于谷歌cse的问题得到的答案很少

<script src="http://www.google.com/jsapi" type="text/javascript"></script>

google.load('search', '1'); 
google.setOnLoadCallback(googlata);


function googlata(){

var customSearchControl = new google.search.CustomSearchControl('015736343358803935205:m2shzyx2lrg'); // change this to your unique ID  
customSearchControl.setResultSetSize(20);
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF); // open results in new window

var options = new google.search.DrawOptions();
options.setAutoComplete(true);
options.enableSearchResultsOnly()   
customSearchControl.draw('cse',options); // set the results div id  

//ottengo keyword searched  
var link= self.location.href;
var inizio = link.search("q=")+2;
var fine= link.search("&");
var keyword= (link.slice(inizio,fine)).replace('+',' ');
//

customSearchControl.setNoResultsString("<div style='padding:10px'><h2><b>Nessuno risultato per: &nbsp; "+keyword+" </b></h2><br><h3>Prova a cercare qualcosa di simile, siamo certi che potrai trovare cio' che ti interessa!</h3><br><br><br>Se il problema persiste non esitare a <a href='http://www.mywebsite.com/Contattaci'>contattarci</a>, provvederemo il prima possibile.</div>");

customSearchControl.execute(keyword);    
var newlink= link.replace('&sa=Search',''); 
history.pushState({}, null, newlink);   
}

<div id="cse" style="width:100%;">Loading</div>

load('search','1');
setOnLoadCallback(googlata);
函数googlata(){
var customSearchControl=new google.search.customSearchControl('015736343358803935205:m2shzyx2lrg');//将其更改为您的唯一ID
customSearchControl.setResultSetSize(20);
customSearchControl.setLinkTarget(google.search.search.LINK_TARGET_SELF);//在新窗口中打开结果
var options=new google.search.DrawOptions();
选项。设置自动完成(true);
options.enableSearchResultsOnly()
customSearchControl.draw('cse',options);//设置结果div id
//搜索ottengo关键字
var link=self.location.href;
var=link.search(“q=”)+2;
var fine=链接搜索(“&”);
var关键字=(link.slice(inziio,fine)).replace(“+”,”);
//
customSearchControl.setNoResultsString(“Nessuno risultato per:“+关键字+”
提供类似的服务质量,并证明首席信息官的利益!


如果问题持续存在,则提供可能的服务。”); customSearchControl.execute(关键字); var newlink=link.replace(‘&sa=Search’,“”); pushState({},null,newlink); } 加载
在我的例子中,结果将绘制在
div id=“cse”

使用
options.enableSearchResultsOnly()
我只绘制了结果页面,因此我的搜索栏是一个普通的搜索栏,在这里我使用get方法发送数据,实际上在我的函数
googlata()
中,我通过url(关键字)获取数据,然后更改url,因为我想要一个干净的url

了解谷歌搜索的API 2.0非常重要,我建议阅读:

意大利再见D