所以我正在为 ckeditor (@mentions) 编写一个插件。
当您键入一些字符(例如“@John”)时,将出现一个下拉菜单,其中包含用户可以选择的 John 列表。当用户选择他们想要的下拉列表时,它需要删除“@John”文本并插入从下拉列表中检索到的元素。尝试插入文本、删除一些文本和设置光标位置时会出现问题。
代码
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();
问题
这在 chrome 上工作得很好,但是在删除文本后在 IE11 上,当我尝试访问 mentions.editor.getSelection() 时,我收到“权限被拒绝”错误。我无法设置书签,焦点移动到 ckeditor 的开头。
[更新] 我进行的进一步测试缩小了问题范围。注释掉 mentions.editor.setData(edata); 行它停止错误。如果我在编辑器实例上使用 setData 函数,然后尝试在编辑器实例上运行 GetSelection(),它会在 IE11 中出错(权限被拒绝),但在 Chrome 中有效。似乎 setData 函数在 IE11 中以某种方式锁定了编辑器?我简化了代码以使其更容易复制。
最佳答案
Editor#setData
是一个异步函数。您不能在设置数据后立即使用选择 - 您必须等到一切准备就绪。因此 setData
接受回调。
mentions.editor.setData( edata, function() {
//set the bookmark
mentions.editor.getSelection().selectBookmarks(tempBookMark);
//focas on that position
mentions.editor.focus();
} );
关于javascript - CKEDITOR 4.3.2 IE11 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21648230/