2011-06-25 18 views
3

我有一個谷歌網站搜索谷歌的免費網站搜索,後查詢

http://www.google.com/cse/manage/create

這給了我下面的工作代碼:

<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('013080392637799242034:ichqh_hal4w'); 
     customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); 
     customSearchControl.draw('cse'); 
    }, true); 
</script> 

在我的一些網頁,我有一個搜索框。我可以在該搜索框中輸入文字,發佈到此網站搜索腳本並加載嗎?

例如:

  • 用戶在Home.html中
  • 他們在搜索框中
  • 重定向輸入文本他們Search.html
  • Search.html他們需要輸入的文字,使用它進行搜索,而不需要在空盒子中重新輸入它

目前我有:

// Temporary measure 
SearchBox.click(function (event) { 
    SearchBox.attr('disabled', 'disabled'); 
    SearchBox.css("background", "#efefef"); 
    window.location.replace(Domainroot + "/search"); 
}); 

這是不理想的,但工作正常。當用戶點擊搜索框時,它會將它們重定向到搜索頁面,以保存它們雙重輸入查詢。

感謝您的幫助!

回答

0

一種方法是讓iFrame代碼在您的主頁上,您可以自定義它。你會找到各種方式來做到這一點。但是,如果您想要像搜索框那樣更具個性化的內容,然後在您的網頁上顯示結果,那麼我會建議您執行後端程序來查詢Google,然後回傳結果。檢查Nokogiri的例子是什麼意思。