CKEditor instance already exists

前端 未结 30 3436
刺人心
刺人心 2020-11-27 11:24

I am using jquery dialogs to present forms (fetched via AJAX). On some forms I am using a CKEditor for the textareas. The editor displays fine on the first load.

Whe

相关标签:
30条回答
  • 2020-11-27 12:02

    This is what worked for me:

    for(name in CKEDITOR.instances)
    {
      CKEDITOR.instances[name].destroy()
    }
    
    0 讨论(0)
  • 2020-11-27 12:02

    I've prepared my own solution based on all above codes.

          $("textarea.ckeditor")
          .each(function () {
    
                    var editorId = $(this).attr("id");
    
                    try {    
                        var instance = CKEDITOR.instances[editorId];
                        if (instance) { instance.destroy(true); }
    
                    }
                    catch(e) {}
                    finally {
                        CKEDITOR.replace(editorId);
                    }
                });
    

    It works perfectly for me.

    Sometimes after AJAX request there is wrong DOM structure. For instace:

    <div id="result">
       <div id="result>
       //CONTENT
       </div>
    </div>
    

    This will cause issue as well, and ckEditor will not work. So make sure that you have correct DOM structure.

    0 讨论(0)
  • 2020-11-27 12:03

    Indeed, removing the ".ckeditor" class from your code solves the issue. Most of us followed the jQuery integration example from the ckeditor's documentation:

    $('.jquery_ckeditor')
    .ckeditor( function() { /* callback code */ }, { skin : 'office2003' } );
    

    and thought "... maybe I can just get rid or the '.jquery_' part".

    I've been wasting my time tweaking the callback function (because the {skin:'office2003'} actually worked), while the problem was coming from elsewhere.

    I think the documentation should mention that the use of "ckeditor" as a class name is not recommended, because it is a reserved keyword.

    Cheers.

    0 讨论(0)
  • 2020-11-27 12:04

    Its pretty simple. In my case, I ran the below jquery method that will destroy ckeditor instances during a page load. This did the trick and resolved the issue -

    JQuery method -

    function resetCkEditorsOnLoad(){
    
        for(var i in CKEDITOR.instances) {
            editor = CKEDITOR.instances[i];
                editor.destroy();
                editor = null;
        }
    }
    
    $(function() {
    
                $(".form-button").button();
        $(".button").button();
    
        resetCkEditorsOnLoad(); // CALLING THE METHOD DURING THE PAGE LOAD
    
                .... blah.. blah.. blah.... // REST OF YOUR BUSINESS LOGIC GOES HERE
    
           });
    

    That's it. I hope it helps you.

    Cheers, Sirish.

    0 讨论(0)
  • 2020-11-27 12:04

    Try this:

    for (name in CKEDITOR.instances)
    {
        CKEDITOR.instances[name].destroy(true);
    }
    
    0 讨论(0)
  • 2020-11-27 12:06

    I had the same problem where I was receiving a null reference exception and the word "null" would be displayed in the editor. I tried a handful of solutions, including upgrading the editor to 3.4.1 to no avail.

    I ended up having to edit the source. At about line 416 to 426 in _source\plugins\wysiwygarea\plugin.js, there's a snippet like this:

    iframe = CKEDITOR.dom.element.createFromHtml( '&lt;iframe' + ... + '></iframe>' );
    

    In FF at least, the iframe isn't completely instantiated by the time it's needed. I surrounded the rest of the function after that line with a setTimeout function:

    iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' + ... + '></iframe>' );
    setTimeout(function()
    { 
        // Running inside of Firefox chrome the load event doesn't bubble like in a normal page (#5689)
        ...
    }, 1000);
    
    };
    
    // The script that launches the bootstrap logic on 'domReady', so the document
    ...
    

    The text renders consistently now in the modal dialogs.

    0 讨论(0)
提交回复
热议问题