1

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()"/>
FFish
  • 10,964
  • 34
  • 95
  • 136

2 Answers2

1

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

FFish
  • 10,964
  • 34
  • 95
  • 136
0

Have you considered replacing INSERT-YOUR-KEY with, erm, your key?

Julio Santos
  • 3,837
  • 2
  • 26
  • 47