I am using SWFObject and for the alternative content (no Flash) I want to use a jQuery plugin.
Obviously I want to load jQuery and the plugin script only when Flash is not available. So Google's API Loader seems perfect.
Now I am having issues with the setOnLoadCallback()
event. It seems to be triggered like it should, but maybe before the DOM is ready?
I found another question on SO revealing there is a second undocumented parameter, on DOM load..
but I still can't access jQuery!
<script type="text/javascript" src="https://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script type="text/javascript">
google.load("swfobject", "2.2");
</script>
<script type="text/javascript">
swfobject.embedSWF("slideshow.swf", "slideshow", "800", "530", "7","expressInstall.swf", null, null, null, flashNotLoaded);
function flashNotLoaded(e) {
if (!e.success) {
google.load("jquery", "1.4.2");
google.setOnLoadCallback(jQueryLoaded, true);
}
}
function jQueryLoaded() {
alert("jquery loaded");
$("body").css("background-color","ff00ff"); // does not work....
$(function() {
$("body").css("background-color","ff0000"); // neither does this...
});
}
</script>
EDIT: It seems that google.load for libraries like jQuery is only available on window.load
Only a few of Google own API's can be dynamically loaded with callbacks
See: Google Library API - google.load does not load from event?