谷歌Ajax搜索

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谷歌Ajax搜索相关的知识,希望对你有一定的参考价值。

  1. <script src="http://www.google.com/jsapi?key={google_search_api_key}" type="text/javascript"></script>
  2. <script language="Javascript" type="text/javascript">
  3. //<![CDATA[
  4. var query = '<?php if(isset($_GET['q'])) echo $_GET['q']; ?>';
  5. var noResultsStr = "{no_results_str}"
  6. google.load("search", "1");
  7. // Call this function when the page has been loaded
  8. function initialize() {
  9. // Dynamically load CSS to override defaults
  10. var options = new google.search.SearcherOptions();
  11. options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
  12.  
  13. var siteSearch = new google.search.WebSearch();
  14. //siteSearch.setUserDefinedLabel("{tab_lbl}");
  15. siteSearch.setUserDefinedClassSuffix("siteSearch");
  16. siteSearch.setSiteRestriction("{google_cse}");
  17.  
  18. var searchControl = new google.search.SearchControl();
  19. searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
  20. searchControl.addSearcher(siteSearch, options);
  21. searchControl.setNoResultsString(noResultsStr)
  22.  
  23. // create a drawOptions object
  24. var drawOptions = new google.search.DrawOptions();
  25. // tell the searcher what input field to use
  26. drawOptions.setInput(document.getElementById("{search_input_id}"));
  27. // tell the searcher to draw itself in tabbed mode
  28. drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
  29. searchControl.draw(document.getElementById("searchcontrol"), drawOptions);
  30.  
  31. searchControl.execute(query);
  32. }
  33. google.setOnLoadCallback(initialize);
  34.  
  35. //]]>
  36. </script>

以上是关于谷歌Ajax搜索的主要内容,如果未能解决你的问题,请参考以下文章

是否有像谷歌搜索服务一样返回 JSON 的雅虎搜索服务?

如何更改有关 GSnewsBar 对象(Ajax API)的“谷歌新闻”的语言?

谷歌搜索结果与JavaScript,API

如何在 Python 中下载谷歌图片搜索结果

Ajax--游览器控制台查看通信报文(这里以谷歌游览器为例)

谷歌地图放置自动完成加载事件