views:

34

answers:

1

Hi,

I'm trying to use the Flattr JavaScript API. I included the loading code as described.

But FlattrLoader.setup() does not work. I am getting the exception ReferenceError: FlattrLoader is not defined.

I tried both

<script type="text/javascript">
  FlattrLoader.setup();
</script>

and

<script type="text/javascript"> 
  window.onload = function(){ FlattrLoader.setup(); }
</script>

That is strange because in the load.js from the API, I see var FlattrLoader = { ... }.

I use Chrome. From its Developer Tools, it seems that the load.js gets loaded (at least it lists it there).

Maybe I must do some extra handling that it waits with the execution until the load.js is really loaded? The only explanation why it fails is that the site-loading itself is finished before load.js can be loaded. How would such extra handling look like?

A: 

My current solution:

function loadFlattr() {
    if(typeof(FlattrLoader) == "undefined")
        setTimeout(loadFlattr, 100);
    else
        FlattrLoader.setup(); 
}
loadFlattr();

Is there any better solution?

Albert