0

I am creating joomla templates and want to add a simple jquery script. The problem is that there are other joomla extensions like GCalendar which load their own jquery.

This means:

  1. If I add <script src="http://code.jquery.co.... it will conflict with the jquery of other extensions
  2. If I don't add that code, the new script will not work if other jquery loading extensions are not installed.

Any ideas?

2 Answers 2

1

If you are hosting the library yourself you could wrap the entire library with an

if ( !jQuery ) {
    // jQuery Library
}

Or you could look into a library like RequireJS to handle your dependencies.

Sign up to request clarification or add additional context in comments.

2 Comments

the if didn;t work or I don't know how to use it. How can I add something like "if jquery is loaded do nothing but if there is no jquery load jquery"
Currently my code looks like this: ` <script> if(!window.jQuery) { var script = document.createElement('script'); script.type = "text/javascript"; script.src = "code.jquery.com/jquery-latest.js"; document.getElementsByTagName('head')[0].appendChild(script); } </script> <script type="text/javascript">var $j = jQuery.noConflict();</script> <script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/myjqueryscript.js"></script>`
1

You can check if jQuery is defined in script and load it if it has not been loaded prior.

You may run into functionaliy issues if the previously loaded version of jQuery is not a version you are supporting


<script>window.jQuery || document.write(
        '<script src="/scripts/jquery-1.6.2.min.js"><\/script>')
</script>

1 Comment

can you tell me exactly how to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.