首先,获得API密钥。

Sign-up for an AJAX Search API Key

有一个简单的示例源。

 
<html>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=Your_API_Key" type="text/javascript"></script>
<link href="http://www.google.com/uds/css/gsearch.css" type="text/css" rel="stylesheet"/>
//   search form is unnecessary
<style type="text/css">
.gsc-control form.gsc-search-box {
display :none;
}
</style>
<script type="text/javascript">
function search(div) {
  string = document.getElementById(div).innerHTML;
  var searchControl = new GSearchControl();
  ws = new GimageSearch();
  ws.setUserDefinedLabel(string);
  searchControl.setResultSetSize(  GSearch.LARGE_RESULTSET  )  ;
  var options = new GsearcherOptions();
  options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
  searchControl.addSearcher(ws,options);
  searchControl.draw(document.getElementById(div));
  searchControl.execute(string);
}
function start() {
search("s1");
search("s2");
search("s3");
}
</script>
<body onload="start()">
<table>
<tr>
<td id="s1">world cup</td>
<td id="s2">G20</td>
<td id="s3">oil spill</td>
</tr>
</table>
</html>
 
 
 
 
 
 
 
 
 
 
You can show search results.
 
default number of search results is one.
show 4 results.
searchControl.setResultSetSize(GSearch.SMALL_RESULTSET);  
show 8 results.
searchControl.setResultSetSize(GSearch.LARGE_RESULTSET); 
 
 
 
 
 
 
 K-ON!!輕音部
 
 
 
 
iphone4
 
 
House of Councillors Election
 
 
 
 
 
 
 
 
廣告