How to determine if CKEditor is loaded?

前端 未结 7 1687
野性不改
野性不改 2021-02-18 16:16

How do I find out if CKEditor is loaded? I\'ve looked through the API docs, but could only find the loaded event. I want to check if CKEditor is loaded, because if I load it a s

7条回答
  •  不要未来只要你来
    2021-02-18 16:44

    Hope this helps someone.

    I also load a page snippet with CKEDITOR functionality via AJAX and as such I have experienced many of the problems outlined in this question. This is my solution:

    function setCk(id){
    if(window.CKEDITOR){
        var _instId = CKEDITOR.instances[id];
        if(_instId == undefined){
            CKEDITOR.inline(id);
        }else{
            CKEDITOR.instances[id].destroy();
            CKEDITOR.inline(id);
        }
    }
    

    }

    On each AJAX response for this snippet I inject a script element into the head with a call to setCk(textareaId). The trick being to destroy any previous CKEDITOR instances for the target ID & re-initialise CKEDITOR after each AJAX snippet load.

提交回复
热议问题