How can I load jQuery if it is not already loaded?
April 16, 2014 Leave a comment
Sometimes need to check that in a page jquery already loaded then no need extra jquery or not loaded then need to load jquery, you can do it using simple jquery code. Here is the code
<script type="text/javascript"> var baseurl="shafiqul.wordpress.com"; var doc=document.getElementsByTagName("head").item(0); var jQueryScriptOutputted = false; var jQueryScriptOutputtedplaceholder = false; window.onload=function() { initJQuery(); } function initJQuery() { if (typeof(jQuery) == "undefined") { if (! jQueryScriptOutputted) { jQueryScriptOutputted = true; includeJs("/js/jquery-1.4.4.min.js", true); | } } if (! jQueryScriptOutputtedplaceholder) { jQueryScriptOutputtedplaceholder = true; includeJs("/scripts/html5_placeholder.js", true); } setTimeout("initJQuery()", 100); } function includeJs(fileName, jQ, head){ var js=document.createElement("script"); js.setAttribute("language", "javascript"); js.setAttribute("type", "text/javascript"); js.setAttribute("src", baseurl+fileName); if(jQ===true){ doc.insertBefore(js, doc.firstChild); return false; } if(head===true){ doc.appendChild(js); return false; } document.getElementsByTagName("body").item(0).appendChild(js); return false; } </script>
if you find any problem then please give a comment.
Recent Comments