Home Dojo Dojo Google Web Search
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Dojo Google Web Search

Advertisement
In this section, you will learn how to implement the google web search. That means user enter your text that have to be searched.

Dojo Google Web Search

       

In this section, you will learn how to implement the google web search. That means user enter your text that have to be searched. This program search all content related to its. If you click on the filtered data then you get the specific data.

Try Online: Google Web Search

Here is the code of program:

<html>
<head>
<title>Google Web Search Search Example</title>

  <style type="text/css">
  @import "../dijit/themes/soria/soria.css";
  @import "/resources/dojo.css";
  </style>

  <script type="text/javascript" src="dojo.js" djConfig="parseOnLoad: true"></script>

  <script type="text/javascript">
  dojo.require("dojox.data.GoogleSearchStore");
  dojo.require("dijit.form.Button");

  function doSearch() {
  var queryString = dojo.byId("searchText").value;
  var store = new dojox.data.GoogleWebSearchStore();
  var list = dojo.byId("searchOutput");

  //Clean up previous searches text
  while(list.firstChild){
  list.removeChild(list.firstChild);
  }
  
  store.fetch({query:{text: queryString},count: 25,onComplete: function(items, request) {
  //Print out the search results as an unordered list
  var delay = 0;
  dojo.forEach(items, function(item){
  var li = document.createElement("li");
  li.innerHTML = "<a href=\"" + store.getValue(item, "url")  + "\">" + 
store.getValue(item, "title") + "</a>";
  dojo.style(li, "opacity", "0");
  list.appendChild(li);

  //Fade in the results.
  delay += 500;
  dojo.fadeIn({node:li}).play(delay);  
  });
  }
  });
  }
</script>
</head>

<body class="soria">
<table border="1" cellpadding="0" cellspacing="0" width="600" align="center">
<tr>
<td valign="top" align="CENTER">
<b>Enter your search text:</b>
<input type="text" size="20" value="" id="searchText"/>
<div dojoType="dijit.form.Button" onclick="doSearch();">
  <b>Search</b>
</div>
</td>
</tr>
<tr>
<td valign="top">
<ul id="searchOutput" class="link-list"></ul>
</td>
</tr>
</tr>
</table>
</body>
</html>

Output:

When you run this program:

After entering your text. This program searches the related text from google:

-

Try Online:

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 1, 2008

Ask Questions?    Discuss: Dojo Google Web Search   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com