Skip to content

Instantly share code, notes, and snippets.

@ptone
Created December 12, 2012 19:13
Show Gist options
  • Save ptone/4270659 to your computer and use it in GitHub Desktop.
Save ptone/4270659 to your computer and use it in GitHub Desktop.
load popcorn dynamically
// load popcorn dynamically
var script = document.createElement("script");
script.type = "text/javascript";
script.src = '/static/js/popcorn.js';
document.getElementsByTagName("head")[0].appendChild(script);
function popcornReady() {
// this is called when script loaded, but before Popcorn global ready
console.log("popcorn ready callback");
// console.log(Popcorn);
}
script.onreadystatechange= function () {
if (this.readyState == 'complete') popcornReady();
}
// this also does not work:
script.onload= popcornReady();
window.onload = function() {
//Popcorn is only now available
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment