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

会有一股神秘感。 提交于 2019-12-03 10:30:32

问题


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?


回答1:


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.
});



回答2:


The documentation says:

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



来源:https://stackoverflow.com/questions/2573549/what-does-google-setonloadcallbackinitialize-function-exactly-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!