TinyMCE 内联模式:在编辑器关闭时获取编辑区域的内容

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

我在启用内联模式的情况下使用 TinyMCE 插件。我想做的是在编辑器关闭后获取编辑过的区域的内容。这是我现在拥有的:

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

但是,此操作不会记录任何内容。有什么想法吗?

每次您离开编辑器时,它都会触发 blur 事件 (https://www.tinymce.com/docs/advanced/events/#blur) ...您可以在 TinyMCE 配置中捕获它:

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
        });
    }
});