How can i close CKEditor or tinyMCE on a click outside of the editor?

风流意气都作罢 提交于 2019-12-01 08:40:23

Here's how to remove TinyMCE from a textarea:

tinyMCE.execCommand('mceRemoveControl', false, 'id');

You can also have 'mceAddControl' or 'mceToggleEditor' for more control. 'id' is the id attribute on the textarea.

This should work pending you've initiated TinyMCE in the normal ways, can't be more specific without seeing your source code!

This is the code you would need to place on a button onclick action to close CKEditor

CKEDITOR.instances.editor1.destroy();

CKEditor seems to provide an API to "stopPropagation"

So my solution would be to put an onclick event on the body, but stop propagation of the click event on the editor.

e.g.

var element = CKEDITOR.document.getById( 'myElement' );
element.on( 'click', function( ev )
{
    // The DOM event object is passed by the "data" property.
    var domEvent = ev.data;
    // Prevent the click to chave any effect in the element.
    domEvent.stopPropagation();
});

and the body event will be something like this (well, not exactly, but just to illustrate)

$("body").click(function(event){
    element.destroy();
});

see here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!