Knowledge base
Guides
Academy
Video tutorials
Try searching for:
Recently viewed articles:

Table of contents

Adding Javascript code to Custom HTML modules in Joomla

When adding some custom Javascript in your article or custom HTML module, you might find out that it doesn't work in the front end or even disappears from HTML sources. Please follow these instructions in order to solve such problems.

By default, text editors in Joomla administrator interface work in visual (WYSIWYG) mode. WYSIWYG editors allow editing HTML markup when you just need to publish some text, but when you try to publish a Javascript code through it, it will reformat it in the way that it shows up as a readable text, not as an actual working code. Moreover, there are security settings in Joomla that can prohibit using of Javascript codes within HTML code, in such cases the text editor just strips all <script> blocks.

1. Set up general text filtering options for being able to use Javascript safely inside HTML source editor.

  • Open Content → Article Manager in your Joomla administrator panel and click on the Options button in the top right corner
  • In the popup window with Article Manager Options, open the Text Filters tab and select "No Filtering" under your user group (it is usually "Super Users")
  • Click Save

2. Configure your text editor so that it allows you to have <script> elements in your code.

The text editor that you use in Joomla may set its own security settings, which can affect code formatting. By default, the TinyMCE is used in Joomla administrator interface. Here is how to configure it properly:

  • In your administrator panel, go to Extensions → Plug-in Manager, find the Editors - TinyMCE line and click it
  • In TinyMCE options on right, find the Prohibited elements section and remove the mention of "script" from it
  • Click Save

There can be different filtering settings in different text editors plugins though. For example, if you are using JCE editor, you don't need to change any of its settings, it doesn't strip scripts by default. Please refer to the documentation of the plugin you use.

3. Use the 'HTML' mode when pasting the javascript codes into HTML.

No matter what editor you're using, when trying to insert a javascript code you need to switch the editor into the HTML mode first – look for HTML button or tab somewhere around the editor area. With that mode the codes that you enter into editor are treated as exactly the codes and should work. Joomla administrator interface sometimes also has a Toggle editor button below the actual editor – you can switch from visual to the code editor by hitting that button:

By using the abovementioned recommendations, you'll be able to make Javascript codes work inside your HTML sources in Joomla. If, however, it doesn't help, please feel free to contact our support team.

Related articles

Adding your store to any website
Adding your store to Joomla
Sell on Facebook

Was this article helpful?

Awesome! Thanks for your feedback!

Thanks for your feedback!

Sorry about that! What went wrong?
20 out of 55 found this helpful
10
We use cookies and similar technologies to remember your preferences, measure effectiveness of our campaigns, and analyze depersonalized data to improve performance of our site. By choosing «Accept», you consent to the use of cookies.
Accept cookies Decline