Search code examples
javascripthtmlwordpresstinymce

TinyMCE stripping javascript from link on visual tab


TinyMCE is removing the javascript from the following link when I use the Visual tab.

<a href="/home/" onclick="trackOutboundLink('/home/', 'Home Page', 'link 1'); return false;">Home</a>

The onclick="trackOutboundLink('/home/', 'Home Page', 'link 1'); return false;" code disappears when I go to the Visual tab of TinyMCE. I'm using TinyMCE in the context of Wordpress.

Is possible to use the visual tab of the TinyMCE editor without erasing my javascript code?


Solution

  • TinyMCE editor strips out elements that are not specified as valid. These valid elements are specified during setup of the editor.

    I am not familiar with WordPress, but it sounds like you need to install this WordPress plugin to allow advanced configuration of the TinyMCE editor. This would allow you to specify onlick as a valid attribute for the a tag.

    Also, take a look at this article I found on wordpress.org. This person seemed to be having a similar issue.