Google Library API - google.load does not load from event?
When I load a library from a function it doesn't load and even crashes the page!
What's up with that??HTML head:
<script type="text/javascript" src="https://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script type="text/javascript">
// --- LOADING LIKE THIS WORKS FINE ---
// jQuery is completely loaded
function jqueryLoaded() {
$("body").css("background-color","orange");
}
google.load("jquery", "1.4.3");
google.setOnLoadCallback(jqueryLoaded);
// --- LOADING FROM AN EVENT DOES NOT WORK?? ---
// jQuery UI is completely loaded
function jqueryUILoaded() {
$("body").css("background-color","green");
}
开发者_如何学编程 function loadJqueryUI() {
alert("load jQuery UI now..");
google.load("jqueryui", "1.8.6");
google.setOnLoadCallback(jqueryUILoaded);
}
// with a setTimeout it doesn't work either..
// setTimeout("loadJqueryUI()", 2000);
</script>
HTML body:
<input type="button" value="load jQuery UI" onclick="loadJqueryUI()"/>
Okay, it seems that we can not load jQuery dynamically:
http://code.google.com/apis/loader/#Dynamic
The standard google.load functionality loads the API(s) when your page loads
The only Libraries supported by Google Loader, loaded dynamically and with callbacks are:
- Google Maps API
- Google Search API
- Google Feeds API
- Google Language API
- Google Visualization API
Bummer!
I am going for a lazy-load polling plugin: http://wonko.com/post/lazyload-200-released
Have you considered replacing INSERT-YOUR-KEY
with, erm, your key?
精彩评论