Onclick HTML attribute get stripped out in Code Mode

Hi Mautic community,

Your software
My Mautic version is : 2.16.0
My PHP version is: 7.1.33

Your problem
My problem is:

While composing a landing page in Code Mode I want to capture events that hit some tags in order to attach Javascript functions.
For example, I want to be able to have:
Click Here
(I want to do that to show a pop-up when someone clicks the link.)

The problem is that once I click on Apply in Code Builder, the part onclick=“myFunction()” attribute get stripped out from the HTML code.

Is there a way to keep the Javascript elements in Code Mode? May be by toggling some flag in the config files of Mautic?

Steps I have tried to fix the problem:
I search in the Community Forum but found only hints related to the former editor Froala.


I can confirm this is happening and not sure how to solve it. What you can do as a workaround is to bind the even in javascript rather than adding it to the html.

For example
<button id="myBtn">Click here</button>

Then the javascript would be something like this

document.getElementById("myBtn").onclick = function() {myFunction()};



Thank you @renzof !!

I didn’t though going this way, not a big pro in javascript.

When I tried the solution it didn’t work. I declared the script in the <head>. I realized it was because the element #myBtn was not created in the DOM when the script was parsed. So the script needs to be declared after the HTML element, for example right before </body> and that makes the trick.

Glad to be of help :+1:t3:

1 Like