开发者

Google setOnloadcallback() function clash with window.onload

开发者 https://www.devze.com 2023-03-18 02:33 出处:网络
here is my code: window.onload = function(){ google.load(\"visualization\", \"开发者_C百科1\", {packages:[\"corechart\"]});

here is my code:

window.onload = function(){
  google.load("visualization", "开发者_C百科1", {packages:["corechart"]});
  google.setOnLoadCallback(function(){
    alert("Message");
  });
}

I know it will work if I put google load outside window.onload. But I want it to be inside the window.onload. Any suggestions?

Thanks


As far as I know, the Google loader is using document.write to add scripts to the page. document.write only works before the window has fully loaded, so it seems you can't use google.load inside of window.onload. I'd recommend putting whatever code you need inside of the google.setOnLoadCallback function - window.onload works fine in there.

Alternatively, you can autoload the Google APIs so that the onLoadCallback is unnecessary like this (see docs for more info):

<script type="text/javascript" src="http://www.google.com/jsapi?autoload={modules:[{name:gdata,version:2.x,packages:[blogger]}]}"></script>

Also check out the jQuery library because it has functions like $(document).ready() that improve greatly on window.onload.

0

精彩评论

暂无评论...
验证码 换一张
取 消