Learn how to handle JavaScript issues and prevent errors.
Almost every Joomla extension uses JavaScript, relying on a library like jQuery. Using different scripts on a webpage can cause conflicts between them.
If your website does not work as you expect when you click something or an animation stopped working, this could be due to a script error. In this case the script execution will be stopped by the browser.
The following developer tools show you script-errors including information about what went wrong, the file and line number and the source code that caused the error.
Developer Tools | Description |
---|---|
Browser Debug Console | One way is using the browser's debug console on the page where the error occurs. It will help you to identify the scripts and their related files on your webserver. |
Firebug and other browser WDT | Firebug for Firefox allows you to inspect and non-destructively edit HTML and also includes a powerful JavaScript debugger. Other browsers like Chrome, Safari or Opera already have similar built-in tools. |
Usually the errors are caused by an extension or combination of multiple extensions. If you've detected a JavaScript error on a page, you need to find its origin.
There is an ongoing discussion in the Joomla community on how to prevent loading jQuery multiple times across extensions. We have already taken steps and measures by implementing a widely accepted solution. We register through JApplication whether jQuery is loaded or not. In case a 3rd party extension loads the jQuery library, you can use the following code snippet to prevent ZOO, Widgetkit or Warp theme from loading it twice.
// load jQuery, if not loaded before
if (!JFactory::getApplication()->get('jquery')) {
JFactory::getApplication()->set('jquery', true);
// add jQuery
...
}
Note You can also get in touch with the 3rd party extension developer and kindly ask them to implement this.