星期二, 十二月 16, 2008

google Ajax API 的使用

试了一下google搜索Ajax,发现使用非常方便,主要将下面的示例代码放到html源文件中就可以使用google ajax搜索插件了。

只需改变searchControl.execute("abc");语句中的关键词(abc)就可以改变google
ajax搜索页面显示的搜索结果。简直就是傻瓜式的。

=========================================================

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
google.load("search", "1.0");
function OnLoad() {
// Create a search control
var searchControl = new google.search.SearchControl();

// Add in a full set of searchers
searchControl.addSearcher(new google.search.WebSearch());
searchControl.addSearcher(new google.search.VideoSearch());
searchControl.addSearcher(new google.search.BlogSearch());
searchControl.addSearcher(new google.search.NewsSearch());
searchControl.addSearcher(new google.search.ImageSearch());

// tell the searcher to draw itself and tell it where to attach
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
searchControl.draw(document.getElementById("searchcontrol"), drawOptions);

// execute an inital search
searchControl.execute("abc");
}
google.setOnLoadCallback(OnLoad, true);
//]]>
</script>
<div id="searchcontrol"> Loading </div>

=========================================================

0 comments: