CKEDITOR 4.3.2 IE11权限被拒绝

时间:2014-02-08 16:00:25

标签: javascript ckeditor

所以我正在为ckeditor(@mentions)编写一个插件。

当您键入一些字符(例如“@John”)时,将显示用户可以选择的Johns列表的下拉列表。当用户选择他们想要的下拉列表时,需要删除“@John”文本并插入从下拉列表中检索到的元素。尝试插入文本,删除一些文本和设置光标位置时会出现问题。

守则

var html = '<span>InsertedElement</span>&nbsp;&nbsp;';
// Create the Element to insert
var newElement = CKEDITOR.dom.element.createFromHtml(html, mentions.editor.document);
//Insert the element
mentions.editor.insertElement(newElement);
//Get a new bookmark
var tempBookMark = mentions.editor.getSelection().createBookmarks(true);
// get the data
var edata = mentions.editor.getData();
// set it with the exact same info so not changes (just for the test)
mentions.editor.setData(edata);
//set the bookmark
mentions.editor.getSelection().selectBookmarks(tempBookMark);
//focas on that position
mentions.editor.focus();

问题

这在chrome上运行得很好但是在IE11删除文本后,当我尝试访问mentions.editor.getSelection()时,我得到“权限被拒绝”错误。我无法设置书签,焦点移动到ckeditor的开头。

[更新] 我进行的进一步测试缩小了这个问题。注释掉 mentions.editor.setData(edata); 行,它会停止错误。如果我在编辑器实例上使用setData函数,然后尝试在Editor实例上运行GetSelection(),它在IE11中会出错(权限被拒绝)但在Chrome中有效。似乎setData函数在IE11中以某种方式锁定了编辑器?我已经简化了代码,以便更容易复制。

1 个答案:

答案 0 :(得分:4)

Editor#setData是一个异步函数。设置数据后无法立即使用选择 - 您必须等到一切准备就绪。因此setData接受回调。

mentions.editor.setData( edata, function() {
    //set the bookmark
    mentions.editor.getSelection().selectBookmarks(tempBookMark);
    //focas on that position
    mentions.editor.focus();
} );
相关问题