[jQuery] Re: checking if jquery loaded
I ended up solving this problem by using the lazy load method described here: http://www.squidoo.com/load-jQuery-dynamically I think the loadPlugins() function was being called before jQuery had a chance to fully load, thus causing the errors. On Jan 15, 12:08 pm, Nalum mallon.l...@gmail.com wrote: Hello zendog74, In your script above you have script.onload = loadPlugins();, the onload event is only usable in the body tag or the frameset tag. Other than that I think your script is ok. On Jan 15, 4:44 pm, zendog74 n8cs...@gmail.com wrote: These just give me undefined errors, as jQuery is not defined if it is not loaded. Again, what I need to do is load jQuery if it is not already loaded and then load all of the required plug-ins once it is loaded. On Jan 14, 4:39 pm, waseem sabjee waseemsab...@gmail.com wrote: if(jQuery) { // jquery is loaded} if($) { // jquery is loaded } or if (jQuery != null) { // jquery is loaded} if ($ != null) { // jquery is loaded } On Thu, Jan 14, 2010 at 11:30 PM, zendog74 n8cs...@gmail.com wrote: I am trying to only load jquery and jqueryui if they do not already exist. If they do exist, then I load a bunch of plug-ins used by the app. However, the below is not working and I have no idea why. Can anyone provide some insight? if (typeof jQuery == 'undefined') { console.log(loading local jquery files); var head = document.getElementsByTagName(head)[0]; var script = document.createElement(script); script.type = text/javascript; script.src = /cml/js/jquery.min.js; script.onload = loadPlugins(); head.appendChild(script); var script2 = document.createElement(script); script2.type = text/javascript; script2.src = /cml/js/jquery-ui.min.js; head.appendChild(script2); } function loadPlugins(){ if(typeof jQuery != 'undefined'){ console.log(jquery is defined); jQuery.noConflict(); //load the plugins if(!jQuery().maxlength){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.maxlength-min.js)%/ scr' + 'ipt'); console.log(loaded maxlength plugin); } if(!jQuery().address){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.address-1.1.min.js)%/ scr' + 'ipt'); console.log(loaded address plugin); } if(!jQuery().delay){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.delay.js)%/scr' + 'ipt'); console.log(loaded delay plugin); } if(!jQuery().ajaxSubmit){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.form.js)%/scr' + 'ipt'); console.log(loaded form plugin); } Thanks everyone.
[jQuery] Re: checking if jquery loaded
These just give me undefined errors, as jQuery is not defined if it is not loaded. Again, what I need to do is load jQuery if it is not already loaded and then load all of the required plug-ins once it is loaded. On Jan 14, 4:39 pm, waseem sabjee waseemsab...@gmail.com wrote: if(jQuery) { // jquery is loaded} if($) { // jquery is loaded } or if (jQuery != null) { // jquery is loaded} if ($ != null) { // jquery is loaded } On Thu, Jan 14, 2010 at 11:30 PM, zendog74 n8cs...@gmail.com wrote: I am trying to only load jquery and jqueryui if they do not already exist. If they do exist, then I load a bunch of plug-ins used by the app. However, the below is not working and I have no idea why. Can anyone provide some insight? if (typeof jQuery == 'undefined') { console.log(loading local jquery files); var head = document.getElementsByTagName(head)[0]; var script = document.createElement(script); script.type = text/javascript; script.src = /cml/js/jquery.min.js; script.onload = loadPlugins(); head.appendChild(script); var script2 = document.createElement(script); script2.type = text/javascript; script2.src = /cml/js/jquery-ui.min.js; head.appendChild(script2); } function loadPlugins(){ if(typeof jQuery != 'undefined'){ console.log(jquery is defined); jQuery.noConflict(); //load the plugins if(!jQuery().maxlength){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.maxlength-min.js)%/ scr' + 'ipt'); console.log(loaded maxlength plugin); } if(!jQuery().address){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.address-1.1.min.js)%/ scr' + 'ipt'); console.log(loaded address plugin); } if(!jQuery().delay){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.delay.js)%/scr' + 'ipt'); console.log(loaded delay plugin); } if(!jQuery().ajaxSubmit){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.form.js)%/scr' + 'ipt'); console.log(loaded form plugin); } Thanks everyone.
[jQuery] Re: checking if jquery loaded
Hello zendog74, In your script above you have script.onload = loadPlugins();, the onload event is only usable in the body tag or the frameset tag. Other than that I think your script is ok. On Jan 15, 4:44 pm, zendog74 n8cs...@gmail.com wrote: These just give me undefined errors, as jQuery is not defined if it is not loaded. Again, what I need to do is load jQuery if it is not already loaded and then load all of the required plug-ins once it is loaded. On Jan 14, 4:39 pm, waseem sabjee waseemsab...@gmail.com wrote: if(jQuery) { // jquery is loaded} if($) { // jquery is loaded } or if (jQuery != null) { // jquery is loaded} if ($ != null) { // jquery is loaded } On Thu, Jan 14, 2010 at 11:30 PM, zendog74 n8cs...@gmail.com wrote: I am trying to only load jquery and jqueryui if they do not already exist. If they do exist, then I load a bunch of plug-ins used by the app. However, the below is not working and I have no idea why. Can anyone provide some insight? if (typeof jQuery == 'undefined') { console.log(loading local jquery files); var head = document.getElementsByTagName(head)[0]; var script = document.createElement(script); script.type = text/javascript; script.src = /cml/js/jquery.min.js; script.onload = loadPlugins(); head.appendChild(script); var script2 = document.createElement(script); script2.type = text/javascript; script2.src = /cml/js/jquery-ui.min.js; head.appendChild(script2); } function loadPlugins(){ if(typeof jQuery != 'undefined'){ console.log(jquery is defined); jQuery.noConflict(); //load the plugins if(!jQuery().maxlength){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.maxlength-min.js)%/ scr' + 'ipt'); console.log(loaded maxlength plugin); } if(!jQuery().address){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.address-1.1.min.js)%/ scr' + 'ipt'); console.log(loaded address plugin); } if(!jQuery().delay){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.delay.js)%/scr' + 'ipt'); console.log(loaded delay plugin); } if(!jQuery().ajaxSubmit){ jQuery(head).append('scr' + 'ipt type=text/javascript src= %=response.encodeURL(cntxPath + /js/jquery.form.js)%/scr' + 'ipt'); console.log(loaded form plugin); } Thanks everyone.