如何在Ckeditor中的光标位置放置一个html元素?

时间:2013-05-30 09:19:33

标签: javascript cursor position ckeditor inserthtml

我有成功放置一个html元素的困难,我在我的Ckeditor中拖放。 到目前为止,我刚刚能够使用“setData”将其放在我的内容的最后。 但是我想把它放在我光标的位置。

我的意思是,而不是这样做:

<p>My content with <span>spans</span>, <a>links</a>, etc.</p><span>The html I am drag/droping</span>

我想这样做:

<p>My content with <span>spans</span>, <span>The html I am drag/droping</span>, <a>links</a>, etc.</p>

现在,我的代码看起来像这样:

CKEDITOR.instances['myContent'].insertHtml(' <span>The html I am drag/droping</span>');

我尝试过insertText,但它从未奏效。 然后我尝试了insertHtml,但它只适用于IE o_O。

你知道如何解决它吗? 那将是一个很大的帮助! 感谢。

1 个答案:

答案 0 :(得分:0)

使用Ckeditor'粘贴'(drop)事件/方法而不是本机。

在插件内部编辑.on('instanceReady'... 假设CKEditor 4.x

粘贴和放置由同一事件“粘贴”处理。 Ckeditor将dataValue的内容放在编辑器中的光标位置。

editor.on('paste', function(e){
    // get data from e.data.dataTransfer or wherever ...
    e.data.dataValue = ' <span>The html I am drag/droping</span>';
});