Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript CkEditor-未捕获类型错误:无法读取属性';getSelection';未定义的_Javascript_Jquery_Ckeditor - Fatal编程技术网

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)
     }
  • 我有一份文章清单
  • 每次我点击任何一篇文章,都会打开一个“对话框/模式”
  • 在这样的对话框或模式中,我的文章内容有一个ckeditor元素
  • 当我点击第一个按钮时,它就像一个符咒
  • 问题是在点击第二、第三、第四等按钮后出现的
  • 然后我开始犯这个错误

        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);