| 1 |
/** |
| 2 |
* This function will work cross-browser for loading scripts asynchronously |
| 3 |
*/ |
| 4 |
function loadAsync(src, callback) { |
| 5 |
var scriptTag, |
| 6 |
ready = false; |
| 7 |
|
| 8 |
scriptTag = document.createElement('script'); |
| 9 |
scriptTag.type = 'text/javascript'; |
| 10 |
scriptTag.src = src; |
| 11 |
scriptTag.onreadystatechange = function() { |
| 12 |
// console.log( this.readyState ); //uncomment this line to see which ready states are called. |
| 13 |
if (!ready |
| 14 |
&& (!this.readyState || this.readyState == 'complete') |
| 15 |
) { |
| 16 |
ready = true; |
| 17 |
typeof callback === 'function' && callback(); |
| 18 |
} |
| 19 |
}; |
| 20 |
scriptTag.onload = scriptTag.onreadystatechange |
| 21 |
|
| 22 |
document.getElementsByTagName("head")[0].appendChild(scriptTag) |
| 23 |
} |