Skip to content

Instantly share code, notes, and snippets.

@ddallala
Created November 3, 2010 15:09
Show Gist options
  • Save ddallala/661193 to your computer and use it in GitHub Desktop.
Save ddallala/661193 to your computer and use it in GitHub Desktop.
Loading an External script
/*
* loadExtScript function
*
* http://remysharp.com/2007/04/12/how-to-detect-when-an-external-library-has-loaded/
**************************************/
function loadExtScript(src, test, callback) {
var s = document.createElement('script');
s.src = src;
document.body.appendChild(s);
var callbackTimer = setInterval(function() {
var call = false;
try {
call = test.call();
} catch (e) {}
if (call) {
clearInterval(callbackTimer);
callback.call();
}
}, 100);
}
//-----------------------------------------------------------------------------------------
if(typeof jQuery == 'function')
loadExtScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', function() {
return (typeof jQuery == 'function');
}, myCallbackFunction);
else myCallbackFunction();
//------------ Modify here to add debugger information
function myCallbackFunction() {
console.debug(jQuery('body'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment