Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does google.setOnLoadCallback(initialize) function exactly mean?

While coding JavaScript and Ajax, there is no proper documentation for this function. I searched this term using api src="http://www.google.com/jsapi" and searchControl.execute("abhilashm86");.

How is this google.setOnLoadCallback(initialize) called internally? Is this function just for a new search term when the user clears previous search and starts a new one? How exactly does google.setOnLoadCallback(initialize) get trigerred?

like image 299
Abhilash Muthuraj Avatar asked Apr 04 '10 04:04

Abhilash Muthuraj


2 Answers

Your initialize function will be called when your document (including the Google API) is fully loaded. So you should wrap any code that uses the API in the function you pass in:

E.g.

google.setOnLoadCallback(function()
{
   var searcher = new google.search.SearchControl();
   // More code that depends on the API.
});
like image 182
Matthew Flaschen Avatar answered Oct 18 '22 02:10

Matthew Flaschen


The documentation says:

Use google.setOnLoadCallback to register the specified handler function to be called once the document loads instead of GSearch.setOnLoadCallback.

like image 45
Jason Hall Avatar answered Oct 18 '22 02:10

Jason Hall