You'll need an API key from Google. They are freely available for non-commercial applications.
General Google search box :
<head>
<meta charset="utf-8" />
<title>My GAjax Search</title>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=YOURKEYHERE" type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
//<![CDATA[
function OnLoad() {
// Create a search control
var searchControl = new GSearchControl();
// create a search object
searchControl.addSearcher(new GwebSearch());
// tell Google where to draw the searchbox
searchControl.draw(document.getElementById("search-box"));
}
GSearch.setOnLoadCallback(OnLoad);
//]]>
</script>
</head>
<body>
<!-- Search box -->
<div id="search-box">
</div>
</body>
</html>
Site specific Google search box
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>My GAjax Site Search</title>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=YOURKEYHERE" type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
//<![CDATA[
function OnLoad() {
// Create a search control
var searchControl = new GSearchControl();
// create a search object
var siteSearch = new GwebSearch();
siteSearch.setUserDefinedLabel("YourSite");
siteSearch.setUserDefinedClassSuffix("siteSearch");
siteSearch.setSiteRestriction("example.com");
searchControl.addSearcher(siteSearch);
// tell Google where to draw the searchbox
searchControl.draw(document.getElementById("search-box"));
}
GSearch.setOnLoadCallback(OnLoad);
//]]>
</script>
</head>
<body>
<!-- Search box -->
<div id="search-box">
</div>
</body>
</html>
0 komentar:
Posting Komentar
Click to see the code!
To insert emoticon you must added at least one space before the code.