Created
November 3, 2010 15:09
-
-
Save ddallala/661193 to your computer and use it in GitHub Desktop.
Loading an External script
This file contains hidden or 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
| /* | |
| * 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