Google AJAX 搜尋 API
文檔:http://code.google.com/intl/zh-CN/apis/websearch/docs/
<!DOCTYPE html><html><head><title>Google AJAX 搜尋 API</title><style type="text/css">#searchcontrol .gsc-control{width: 100%;}#searchcontrol .gsc-result-cnblogs .gs-title{color:Red;}</style><script src="https://www.google.com/jsapi?key=ABQIAAAAWUT8aaIj9mtqQa087LjVOhTPB5B7LRDljl2Cr4-JwBNft1mFrRRmR1RoYEUCZCj0dtS2gIc8Al4-VA"type="text/javascript"></script><script language="Javascript" type="text/javascript">google.load("search", "1");function OnLoad() {//搜尋設定var options = new google.search.SearcherOptions();//當搜尋結果為空白時顯示內容options.setNoResultsString('查詢結果為空白!');//搜尋控制項執行個體化var searchControl = new google.search.SearchControl();//每次顯示8個搜尋結果(取值範圍:1-8)searchControl.setResultSetSize(8);//網頁搜尋var siteCnblogs = new google.search.WebSearch();//標題siteCnblogs.setUserDefinedLabel("部落格園");//樣式尾碼名siteCnblogs.setUserDefinedClassSuffix("cnblogs");//網站限制siteCnblogs.setSiteRestriction("www.cnblogs.com");searchControl.addSearcher(siteCnblogs, options);//局部搜尋var siteZjfree = new google.search.WebSearch();siteZjfree.setUserDefinedLabel("自由自在");siteZjfree.setSiteRestriction("www.cnblogs.com/zjfree");searchControl.addSearcher(siteZjfree, options);//全網搜尋searchControl.addSearcher(new google.search.WebSearch(), options);//添加部落格搜尋searchControl.addSearcher(new google.search.BlogSearch(), options);//添加視頻搜尋searchControl.addSearcher(new google.search.VideoSearch(), options);//添加新聞搜尋searchControl.addSearcher(new google.search.NewsSearch(), options);//添加圖片搜尋searchControl.addSearcher(new google.search.ImageSearch(), options);//添加本地地圖搜尋var localSearch = new google.search.LocalSearch();//地圖中心標記 測試時可使用“大雁塔”localSearch.setCenterPoint("西安,鐘樓");searchControl.addSearcher(localSearch, options);//繪製搜尋var drawOptions = new google.search.DrawOptions();drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);searchControl.draw(document.getElementById("searchcontrol"), drawOptions);//執行搜尋查詢searchControl.execute("google api");}//架構載入完成後調用google.setOnLoadCallback(OnLoad);</script></head><body><div id="searchcontrol">載入中...</div></body></html>
效果如下:
載入中...
[返回GOOGLE API學習目錄]