Deka87 Deka87 - 17 days ago 4
Javascript Question

TinyMCE Inline mode: Get content of edited area on editor closing

I use TinyMCE plugin with inline mode on. What I want to do is get the content of the area that's been edited after the editor has been closed. This is what I have for now:

tinymce.init({
selector: '.editable',
plugins: "link",
inline: true,
init_instance_callback: function (editor) {
editor.on('GetContent', function (e) {
console.log(e.content);
});
}
});


However, this on doesn't log anything. Any ideas?

Answer

Each time you leave the editor it fires the blur event (https://www.tinymce.com/docs/advanced/events/#blur) ... and you can capture this in your TinyMCE configuration:

tinymce.init({
    selector: '#my_div",
    ...
    setup: function (editor) {
        editor.on('blur', function (e) {
          console.log('Editor was blurred!');
          // Do what you want when the editor is blurred here
          console.log(editor.getContent());  //get the content from the editor
        });
    }
});