Google AJAX search API implementation code

Source: Internet
Author: User

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

Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<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 ();
// The content is displayed when the search result is empty.
Options. setNoResultsString ('query result is blank! ');

// Search control instantiation
Var searchControl = new google. search. SearchControl ();
// Display 8 search results each time (value range: 1-8)
SearchControl. setResultSetSize (8 );

// Webpage Search
Var siteCnblogs = new google. search. WebSearch ();
// Header
SiteCnblogs. setUserDefinedLabel (" ");
// Style suffix
SiteCnblogs. setUserDefinedClassSuffix ("jb51 ");
// Site restrictions
SiteCnblogs. setSiteRestriction ("jb51.net ");
SearchControl. addSearcher (siteCnblogs, options );

// Partial search
Var siteZjfree = new google. search. WebSearch ();
SiteZjfree. setUserDefinedLabel ("material search ");
SiteZjfree. setSiteRestriction ("SC .jb51.net ");
SearchControl. addSearcher (siteZjfree, options );

// Search all over the network
SearchControl. addSearcher (new google. search. WebSearch (), options );

// Add a blog search
SearchControl. addSearcher (new google. search. BlogSearch (), options );

// Add a Video Search
SearchControl. addSearcher (new google. search. VideoSearch (), options );

// Add news search
SearchControl. addSearcher (new google. search. NewsSearch (), options );

// Add Image Search
SearchControl. addSearcher (new google. search. ImageSearch (), options );

// Add a local map search
Var localSearch = new google. search. LocalSearch ();
// You can use the "Big Wild Goose Pagoda" When marking the map center"
LocalSearch. setCenterPoint ("Xi'an, Bell Tower ");
SearchControl. addSearcher (localSearch, options );

// Draw 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.exe cute ("google api ");
}

// Call after the framework is loaded
Google. setOnLoadCallback (OnLoad );
</Script>
</Head>
<Body>
<Div id = "searchcontrol">
Loading...
</Div>
</Body>
</Html>

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.