如何判断CKEditor是否已加载?
如何确定 CKEditor 是否已加载?我查看了API文档,但只能找到loaded事件。我想检查 CKEditor 是否已加载,因为如果我第二次加载它,我的文本区域就会消失。
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 second time, my textareas disapears.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
loaded
事件对我不起作用。instanceReady
有效:The
loaded
event didn't work for me.instanceReady
worked:我不知道是否存在这样的特定属性 - 可能有! - 但您可以使用已加载事件来设置全局标志。这不是很好,但可以完成工作。
您还可以考虑在 CKEDITOR 中设置一些内容,而不是全局变量:
这会更干净一些。
I don't know whether there exists a specific property for this - there might! - but you could use the loaded event to set a global flag. It's not really nice but would do the job.
Instead of a global variable, you could also consider setting something inside
CKEDITOR
:This would be a bit cleaner.
如果实例未准备好,则文本集将被丢弃
在 CkEditor 初始化(此处为版本 4)时,在编辑器准备好处理数据之前,您不应该设置任何数据。
If instance is not ready, the text set would be discarded
On initialization of the CkEditor (version 4 here), you should never set any data before the editor is ready to handle it.
希望这对某人有帮助。
我还通过 AJAX 加载具有 CKEDITOR 功能的页面片段,因此我遇到了这个问题中概述的许多问题。这是我的解决方案:
}
在此片段的每个 AJAX 响应中,我通过调用 setCk(textareaId) 将脚本元素注入到头部。诀窍是销毁目标 ID 和目标 ID 的任何先前的 CKEDITOR 实例。每次加载 AJAX 片段后重新初始化 CKEDITOR。
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:
}
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.
我知道这是一篇非常古老的文章,但在我的研究中它不断出现。我通过
jQuery
动态加载CKEditor
。正如您发现的那样,自从事情开始发生以来,我不想多次加载它。简单的解决方案:
I know this is a very old post, but in my research it kept coming up. I am dynamically loading the
CKEditor
throughjQuery
. I didn't want to load it multiple times since things start happening, as you found out.Simple solution: