因此,我正在为ckeditor编写一个插件(@)。
当您键入一些字符(例如"@John")时,会出现用户可以选择的Johns列表的下拉列表。当用户选择他们想要的下拉列表时,它需要删除"@John“文本,并插入从下拉列表中检索到的元素。当尝试插入文本、删除某些文本和设置currsor位置时,会出现此问题。
代码
var html = '<span>InsertedElement</span> ';
// 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();The issue
但是,在删除文本之后,在IE11上,当我尝试访问mentions.editor.getSelection()时,我会得到“拒绝权限”错误。我无法设置书签并将焦点移到ckeditor的开头。
更新我执行的进一步测试缩小了问题范围。注释掉mentions.editor.setData(edata);行它停止错误。如果我对编辑器实例使用setData函数,然后尝试在编辑器实例上运行GetSelection(),则IE11中的错误(权限被拒绝),但在Chrome中工作。setData函数似乎在某种程度上锁定了IE11中的编辑器?我已经简化了代码,以便更容易地复制它。
发布于 2014-02-10 14:48:34
Editor#setData是一个异步函数。您不能在设置数据之后立即使用选择--您必须等到一切就绪。因此,setData接受回调。
mentions.editor.setData( edata, function() {
//set the bookmark
mentions.editor.getSelection().selectBookmarks(tempBookMark);
//focas on that position
mentions.editor.focus();
} );https://stackoverflow.com/questions/21648230
复制相似问题