Google AJAX Search API to implement code _JAVASCRIPT skills

Source: Internet
Author: User

Google AJAX Search API
Documents: http://code.google.com/intl/zh-CN/apis/websearch/docs/

Copy Code code as follows:

<! DOCTYPE html>
<title>google AJAX Search 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 () {
Search Settings
var options = new Google.search.SearcherOptions ();
Display content when search results are empty
Options.setnoresultsstring (' query result is empty! ');

Search Control instantiation
var SearchControl = new Google.search.SearchControl ();
Show 8 results per display (Value range: 1-8)
Searchcontrol.setresultsetsize (8);

Web Search
var sitecnblogs = new Google.search.WebSearch ();
Headers
Sitecnblogs.setuserdefinedlabel ("cloud-dwelling community");
Style suffix name
Sitecnblogs.setuserdefinedclasssuffix ("jb51");
Site restrictions
Sitecnblogs.setsiterestriction ("Jb51.net");
Searchcontrol.addsearcher (sitecnblogs, Options);

Local Search
var sitezjfree = new Google.search.WebSearch ();
Sitezjfree.setuserdefinedlabel ("Material search");
Sitezjfree.setsiterestriction ("Sc.jb51.net");
Searchcontrol.addsearcher (Sitezjfree, Options);

Full Web Search
Searchcontrol.addsearcher (New Google.search.WebSearch (), options);

Add Blog Search
Searchcontrol.addsearcher (New Google.search.BlogSearch (), options);

Add Video Search
Searchcontrol.addsearcher (New Google.search.VideoSearch (), options);

Add News Search
Searchcontrol.addsearcher (New Google.search.NewsSearch (), options);

Add a picture search
Searchcontrol.addsearcher (New Google.search.ImageSearch (), options);

Add Local Map Search
var localsearch = new Google.search.LocalSearch ();
"Wild Goose Pagoda" can be used in Map center marking test
Localsearch.setcenterpoint ("Xian, bell Tower");
Searchcontrol.addsearcher (Localsearch, Options);

Draw a search
var drawoptions = new Google.search.DrawOptions ();
Drawoptions.setdrawmode (Google.search.SearchControl.DRAW_MODE_TABBED);
Searchcontrol.draw (document.getElementById ("SearchControl"), drawoptions);

Execute search Query
Searchcontrol.execute ("Google API");
}

Call after frame load completes
Google.setonloadcallback (OnLoad);
</script>
<body>
<div id= "SearchControl" >
In load ...
</div>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.