Why does google.load cause my page to go blank?

前端 未结 5 1764
花落未央
花落未央 2020-11-29 02:45

Well, this looks strange but I\'m not able to find a solution.

Why in the world does this fiddle http://jsfiddle.net/carlesso/PKkFf/ show the page content and, then

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 03:06

    Looks like google.load is adding the script to the page using a document.write(), which if used after the page loads, wipes out the html.

    This explains more in-depth: http://groups.google.com/group/google-ajax-search-api/browse_thread/thread/e07c2606498094e6

    Using one of the ideas, you could use a callback for the load to force it use append rather than doc.write:

    setTimeout(function(){google.load('visualization', '1', {'callback':'alert("2 sec wait")', 'packages':['corechart']})}, 2000);
    

    This demonstrates the 2 second wait with the delayed alert window

提交回复
热议问题