Himberjack
Himberjack

Reputation: 5802

fb.init events when initialized

I have this code

 window.fbAsyncInit = function() {
                FB.init({
                    appId: 'balblablablbal',
                    status: true, 
                    cookie: true, 
                    xfbml: false
                });
            };

            (function() {
                var e = document.createElement('script');
                e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
                e.async = true;
                document.getElementById('fb-root').appendChild(e);
            } ());

I would like to do something only after those JSs have been loaded (i.e. hook on FB.init event)

How can I do that

thanks

Upvotes: 1

Views: 983

Answers (1)

Hemlock
Hemlock

Reputation: 6210

This is not a simple problem, but there are a lot of people tackling it.

Here is a solution with no need for a library (first hit on Google when searching "javascript detect dynamic script load"): http://www.ejeliot.com/blog/109

There are also libraries that do this. Here are a couple that come to mind:

http://headjs.com/

https://github.com/rgrove/lazyload/

Good luck!

Upvotes: 1

Related Questions