Skip to content

Instantly share code, notes, and snippets.

@djmitche
Created March 25, 2010 18:33
Show Gist options
  • Select an option

  • Save djmitche/343932 to your computer and use it in GitHub Desktop.

Select an option

Save djmitche/343932 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Google AJAX Search API Application</title>
<script src="http://www.google.com/jsapi?key=<***insert your key here***>" type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
//<![CDATA[
google.load("search", "1");
var searcher;
var image;
function gotpics() {
if (searcher.results.length == 0) {
OnLoad();
}
var url = searcher.results.pop().url;
document.getElementById('pic').src = url;
document.getElementById('url').innerText = url;
document.getElementById('pic').onload = function () {
window.setTimeout(gotpics, 1000);
};
document.getElementById('pic').onerror = function () {
gotpics();
};
};
function OnLoad() {
searcher = new google.search.ImageSearch();
searcher.setResultSetSize(google.search.Search.LARGE_RESULTSET);
searcher.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE, google.search.ImageSearch.IMAGESIZE_MEDIUM);
searcher.setSearchCompleteCallback(searcher, gotpics);
searcher.execute("Ada Lovelace");
};
google.setOnLoadCallback(OnLoad);
//]]>
</script>
</head>
<body>
<center><img height="80%" id="pic" /><br /><span id="url">Loading..</span></center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment