Javascript CkEditor-未捕获类型错误:无法读取属性';getSelection';未定义的
我正在我的应用程序中实现Javascript CkEditor-未捕获类型错误:无法读取属性';getSelection';未定义的,javascript,jquery,ckeditor,Javascript,Jquery,Ckeditor,我正在我的应用程序中实现CKEditor。当我试图将CKEditor实例化到textarea时,我遇到以下错误 Cannot read property 'getSelection' of undefined 在编辑器的下一行 getNative: function() { return void 0 !== this._.cache.nativeSel ? this._.cache.nativeSel : this._.cache.nativeSel = B ? this.document
CKEditor
。当我试图将CKEditor
实例化到textarea时,我遇到以下错误
Cannot read property 'getSelection' of undefined
在编辑器的下一行
getNative: function() {
return void 0 !== this._.cache.nativeSel ? this._.cache.nativeSel : this._.cache.nativeSel = B ? this.document.$.selection : this.document.getWindow().$.getSelection() }
非常感谢您的帮助。将ckeditor.js中的函数f.$.onload更改为以下内容
f.$.onload=function(){var toutMs =5000;
if(CKEDITOR.document.getHead().$.childElementCount > 6)
{
toutMs=0;
}
setTimeout(function(){
A(b,!0)
},toutMs)
}
TypeError: Cannot read property 'getSelection' of undefined
at CKEDITOR.dom.selection.getNative (ckeditor.js:448)
at new CKEDITOR.dom.selection (ckeditor.js:446)
at a.CKEDITOR.editor.getSelection (ckeditor.js:443)
at new CKEDITOR.plugins.undo.Image (ckeditor.js:1182)
at CKEDITOR.plugins.undo.UndoManager.save (ckeditor.js:1177)
at a.<anonymous> (ckeditor.js:1173)
at a.n (ckeditor.js:10)
at a.CKEDITOR.event.CKEDITOR.event.fire (ckeditor.js:12)
at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
at a.setData (ckeditor.js:275)
我得到了同样的错误,我通过初始化CKEditor解决了,在
$(document.function(ready())代码>
我认为,当您在页面加载之前初始化时,它找不到dom元素(textarea)您可以试一试
CKEditor.destroy()代码>这可能是您的应用程序试图在编辑器准备就绪之前访问并设置CKEditor的数据。这可能是竞争条件的结果,导致错误是间歇性的。您可以采取一些措施来防止此问题
首先,测试编辑器是否已加载的方法
if ( CKEDITOR.status == 'loaded' ) {
// The API can now be fully used.
doSomething();
} else {
// Wait for the full core to be loaded and fire its loading.
CKEDITOR.on( 'load', doSomething );
CKEDITOR.loadFullCore && CKEDITOR.loadFullCore();
}
其次,如果无法控制与编辑器值设置相关联的计时,则可以将CKEDITOR.dom.window
对象包装在异步/等待承诺中,测试编辑器是否先加载,如果未加载,则侦听编辑器加载,然后完成值设置。(注意,此代码未经过完全测试)
我花了20分钟写了上面的说明,一个天才把它改成了负数??。。你应该看到我的脚本在工作。我如何向stackoverflow报告?这?。我成功地使用了您的代码,除了其他原因,它在$(document).ready()中工作得更好。
$(document).ready(function () {
CKEDITOR.replace('editor1', {
language: 'tr',
height: '300'
});
});
if ( CKEDITOR.status == 'loaded' ) {
// The API can now be fully used.
doSomething();
} else {
// Wait for the full core to be loaded and fire its loading.
CKEDITOR.on( 'load', doSomething );
CKEDITOR.loadFullCore && CKEDITOR.loadFullCore();
}
CKEDITOR.dom.window = (function(window) {
if ( CKEDITOR.status == 'loaded' ) {
// The API can now be fully used.
return window;
} else {
return (async function() {
return await function() {
return new Promise(resolve => {
CKEDITOR.on( 'load', () => {
resolve(window);
});
});
};
})();
CKEDITOR.loadFullCore && CKEDITOR.loadFullCore();
}
})(CKEDITOR.dom.window);