
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.24 KB | hits: 10 | expires: Never
Dynamically Loading JQuery form an externally linked to JavaScript file
if (typeof jQuery == 'undefined') {
//alert('No jQuery! Will attempt to load it now');
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
tryReady = function(time_elapsed) {
if (typeof jQuery == "undefined") { // if jQuery isn't loaded yet...
if (time_elapsed <= 100000) { // and we havn't given up trying...
setTimeout("tryReady(" + (time_elapsed + 200) + ")", 200); // set a timer to check again in 200 ms.
} else {
alert('hello'); // If this isn't here, the subsequent scripts fail to access jQuery
}
} else {
//alert ("jQuery wasn't but now is loaded")
}
}
tryReady();
}
// Functions making use of jQuery go here...
if (typeof jQuery == 'undefined') {
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js";
script.onload = function(){
alert('voila');
}
document.getElementsByTagName('head')[0].appendChild(script);
}