i have a custom joomla template which i load jquery in using the normal <script></script>
tages. I have installed a plugin which also loads jquery, meaning that jquery is being loaded twice. the plug in is only loaded on a few pages but i require jquery on every page so can't take it out the template. what is the best way to stop it load开发者_JAVA百科ing jquery twice?
Use this javascript code///
if (typeof jQuery == 'undefined') { var head = document.getElementsByTagName("head")[0]; script = document.createElement('script'); script.id = 'jQuery'; script.type = 'text/javascript'; script.src = 'js/jquery.js'; head.appendChild(script); } else { // jQuery is loaded already need not include it... }
typeOf operator checks if the jQuery object already exists if it does not exist then create a script element and append it to head of the html.
精彩评论