Click event on TinyMCE 4.0

11,927

TinyMCE v4 has changed things from v3 - try:

setup : function(ed) {
    ed.on("click", function() {
        alert("Editor Clicked!  Element: " + this.target.nodeName);
    });
};
Share:
11,927
Scipius2012
Author by

Scipius2012

Updated on July 28, 2022

Comments

  • Scipius2012
    Scipius2012 almost 2 years

    Recently I tried to integrate TinyMce 4.0 in my web application. I want to put a click event for when I click on the textarea but it doesn't work. I have looked on the official documentation, and I've tried the following code:

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

    There are an error that appear : "TypeError: ed.onClick is undefined".

    So, I have tried to put directly a onclick event on the iframe but it's a failure :

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

    Do you have any ideas on how to do this?

  • Scipius2012
    Scipius2012 about 11 years
    Thank you for your answer! I've tried your code but I've the following error: "ReferenceError: ed is not defined". I even tried (to test) to replace "ed" to "window.tinyMCE.get("idOfMyTextarea")" and I've again the previous error.
  • Scipius2012
    Scipius2012 about 11 years
    I've tried your code: it works fine for the version 3 but not for the version 4. When I try with the version 4, I've the following error: "TypeError: ed.onInit is undefined". The error appears only on the version 4!
  • Thariama
    Thariama about 11 years
    hmmm, i am not familiar with the new version 4 that much by now - sorry
  • psulek
    psulek about 10 years
    Important to mention that parameter ed in function for 'click' does not contains editor instance. This was my case for 'init' event handling. To access editor instance (originator of event), use - this keyword, eg: editor.on('init', function () { var doc = this.contentDocument; });