Method One:
//Only do anything if jQuery isn ' t definedif(typeofJQuery = = ' undefined ') { if(typeof$ = = ' function ') { //warning, global varThispageusingotherjslibrary =true; } functiongetScript (URL, success) {varScript = document.createelement (' script '); SCRIPT.SRC=URL; varHead = document.getElementsByTagName (' head ') [0], done=false; //Attach handlers for all browsersScript.onload = Script.onreadystatechange =function() { if(!done && (!) This. readyState | | This. readyState = = ' Loaded ' | | This. readyState = = ' complete ') ) { done=true; //callback function provided as Paramsuccess (); Script.onload= Script.onreadystatechange =NULL; Head.removechild (script); }; }; Head.appendchild (script); }; GetScript (' Http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js ',function() { if(typeofjquery== ' undefined ') { //Super Failsafe-still somehow failed ... } Else { //JQuery loaded! Make sure-noconflict just in caseFancycode (); if(thispageusingotherjslibrary) {//Run your jQuery Code } Else { //Use . Noconflict () and then run your jQuery Code } } }); } Else{//JQuery was already loaded //Run your jQuery Code};//The code snippet is from: http://www.sharejs.com/codes/javascript/4281
Method Two: Document.Write
varjqueryscriptoutputted =false;functionInitjquery () {//if the JQuery object isn ' t available if(typeof(jQuery) = = ' undefined ') { if(!jqueryscriptoutputted) { //Only output the script once .jqueryscriptoutputted =true; //output the script (load it from Google API)document.write ("<SCR" + "IPT type=" Text/javascript "src=" http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/ Jquery.min.js "></SCR" + "ipt>"); } setTimeout ("Initjquery ()", 50); } Else { $(function() { //Do anything this needs to being done on Document.ready //don ' t really need this dom ready thing if used in footer }); }}initjquery ();//The code snippet is from: http://www.sharejs.com/codes/javascript/4281
Determine if jquery has been loaded, if not dynamically loaded