Is it ok to use google.setOnLoadCallback multiple times?

巧了我就是萌 提交于 2019-11-29 06:27:11

I may be missing the point here but there's no clash between your usercontrols $(document).ready and google.setOnLoadCallback that I know of.

Assuming you're using google to load jquery, your code in the $(document).ready won't run until google has loaded jquery anyway.

So long as jQuery is being loaded in your masterpage, not sure what the issue is.

Yes, you may use setOnLoadCallback in lieu of $(document).ready. There is an undocumented SECOND PARAMETER (or at least, I can't find it) that specifies when to call the callback function; possible values are "false" (default) - on the window load, or "true" - on DOM load (DOMContentLoaded). The DOM event fires once all the markup has loaded (much earlier than window.load). The window load event fires after all the images and scripts and such have finished loading.

// Very similar to $(document).ready()
google.setOnLoadCallback( OnLoad, true );

// Very similar to $(window).load()
// Same as google.setOnLoadCallback( OnLoad, false );
google.setOnLoadCallback( OnLoad );

Yes, you may use setOnLoadCallback multiple times on a single page. This is a very important undocumented feature of the AJAX API (undocumented as of this posting). Every time you call setOnLoadCallback, it stacks up all the functions to be called once the DOM or window loads.

Adam Coller

I ran into the same problem. I googled have 2 google search running on one page, etc...

In the end i found this and because i wanted to have 2 panels essentially showing google search results on one page.

google.setOnLoadCallback(LoadGoogleNewsResults);
google.setOnLoadCallback(LoadGoogleNewsResultsForum);

This worked for me :)

The code is on http://login.debt-line.org.uk, just click view source.

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