-
-
Save phalkunz/2411184 to your computer and use it in GitHub Desktop.
Async loading of javascript with callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(d, s) { | |
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id, callback) { | |
if (d.getElementById(id)) {return;} | |
js = d.createElement(s);js.src = url;js.id = id;js.async=true; | |
fjs.parentNode.insertBefore(js,fjs); | |
if(callback!=undefined) { | |
js.onload=callback; | |
//Extra for internet explorer | |
js.onreadystatechange = function () { if(this.readyState == 'complete' || this.readyState == 'loaded') { callback(); } } | |
} | |
}; | |
load('//connect.facebook.net/en_US/all.js#xfbml=1', 'fbjssdk', function(){_ga.trackFacebook()}); | |
load('https://apis.google.com/js/plusone.js', 'gplus1js'); | |
load('//platform.twitter.com/widgets.js', 'tweetjs', function(){_ga.trackTwitter()}); | |
}(document, 'script')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment