Click event on TinyMCE 4.0

I recently tried to integrate TinyMce 4.0 into my web application. I want to put a click event when I click on a text field, but it does not work. I looked at the official documentation and I tried the following code:

tinyMCE.init({
   ...
   setup : function(ed) {
      ed.onClick.add(function(ed, e) {
          console.debug('Editor was clicked: ' + e.target.nodeName);
      });
   }

You will receive an error message: "TypeError: ed.onClick is undefined".

So, I tried to put the onclick event directly in the iframe, but this fails:

$("iframe").contents().bind('click', function(){
...
});

Do you have any ideas on how to do this?

+5
source share
2 answers

TinyMCE v4 made a difference with v3 - try:

setup : function(ed) {
    ed.on("click", function() {
        alert("Editor Clicked!  Element: " + this.target.nodeName);
    });
};
+12
source

Hmm you can try

$(ed.getDoc()).bind('click', function(){
...
});

Update: It seems that the editor is not initialized at this point in time. Try

   setup : function(ed) {
      ed.onInit.add(function(ed, e) {
        ed.onClick.add(function(ed, e) {
          console.debug('Editor was clicked: ' + e.target.nodeName);
        });
      });
   }
0
source

All Articles