Google AJAX 搜尋 API實現代碼

來源:互聯網
上載者:User

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("jb51");
//網站限制
siteCnblogs.setSiteRestriction("jb51.net");
searchControl.addSearcher(siteCnblogs, options);

//局部搜尋
var siteZjfree = new google.search.WebSearch();
siteZjfree.setUserDefinedLabel("素材搜尋");
siteZjfree.setSiteRestriction("sc.jb51.net");
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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.