使用 jQuery 从 CKEditor 的 iframe 中获取内容
我有一个自定义编写的 CMS,它使用 CKEditor *(FCKEditor v3) 编辑内容。 我还使用 jQuery 验证用于在基于 AJAX 的提交之前检查所有字段是否有错误的插件。 我使用 serialize() 函数来传递数据到 PHP 后端。
问题是,序列化设法正确获取所有字段,除了在 CKEditor 中输入的实际内容。 与其他所见即所得编辑器一样,该编辑器也将 iframe 覆盖在现有文本框上。 Serialize 会忽略 iframe,只在文本框中查找内容,当然,它找不到内容,因此返回空白内容正文。
我的方法是在 CKEditor 的 onchange 事件上创建一个挂钩,并同时更新文本框 (CKEDITOR.instances.[textboxname].getData()
< /strong> 返回内容)或一些其他隐藏字段以及编辑器中所做的任何更改。
然而,由于 CKEditor 仍处于测试阶段并且严重缺乏文档,我找不到合适的 API 调用来帮助我做到这一点。
有谁知道如何解决这个问题?
I have a custom-written CMS that uses CKEditor *(FCKEditor v3) for editing content. I'm also using the jQuery Validation plugin to check all fields for error prior to AJAX-based submission. I'm using the serialize() function to passing the data to the PHP backend.
Problem is, serialize manages to grab all fields correctly, except for the actual content typed in CKEditor. Like every other WYSIWYG editor, this one too overlays an iframe over an existing textbox. And serialize ignores the iframe and looks only into the textbox for content, which, of course, it doesn't find, thus returning a blank content body.
My approach to this is to create a hook onto the onchange event of CKEditor and concurrently update the textbox (CKEDITOR.instances.[textboxname].getData()
returns the content) or some other hidden field with any changes made in the editor.
However, since CKEditor is still in it's beta stage and severely lacks documentation, I can't find a suitable API call that'll enable me to do so.
Does anyone have any idea on how to go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
另一个通用解决方案是每当您尝试提交表单时运行以下命令
这将强制表单中的所有 CKEDITOR 实例更新其各自的字段
Another generic solutions to this would be to run the following whenever you try to submit the form
This will force all CKEDITOR instances in the form to update their respective fields
我刚刚发布了一个 jQuery 的 CKEditor 插件,它将在后台处理所有这些,无需任何额外的代码:
http://www.fyneworks.com/jquery/CKEditor/
I've just released a CKEditor plugin for jQuery which will take care of all this in the background without any extra code:
http://www.fyneworks.com/jquery/CKEditor/
我今天也一直在努力解决这个问题。 我意识到上面的代码对我不起作用的原因是因为引用文档属性时 CKEditor 实例尚未准备好。 因此,您必须调用“instanceReady”事件,并且在该事件中可以使用文档的事件,因为在此之前它并不存在。
这个例子可能适合你:
I have also been trying to fix this problem today. I realised that the reason the above code isnt working for me is because the CKEditor instance isnt ready yet when the document property is referenced. So you have to call the "instanceReady" event and within that the document's events can be used, because prior to that it just doesnt exist.
This example might work for you:
这应该可以做到...
编辑:添加部分以在粘贴后更新文本框...
This should do it...
edit: added section to update textbox after pastes, too...
我在这方面取得了成功:
I had success with this:
我采取了稍微不同的方法,我认为使用 ckeditor 的更新功能会更好,并且由于使用了 keyup,因此不需要超时
I took a slightly different approach I figured it would be better to use ckeditor's update function and since keyup was being used the timeout wasn't needed
这样做不是更好吗:
ref: http:// /cksource.com/forums/viewtopic.php?f=11&t=18286
Wouldn't it be better to do just this:
ref: http://cksource.com/forums/viewtopic.php?f=11&t=18286
contentDom 事件对我有用,而不是 instanceReady...我真的很想知道事件 ae 是什么,但我认为它们是专有的...
The contentDom event worked for me and not the instanceReady... I would really like to know what the events ae, but I assume they are proprietary...
CKEDITOR.instances.wc_content1.getData()
将返回 ckeditor 数据CKEDITOR.instances.wc_content1.setData()
将设置 ckeditor 数据CKEDITOR.instances.wc_content1.getData()
will return the ckeditor dataCKEDITOR.instances.wc_content1.setData()
will set the ckeditor data我认为用户在询问序列化,我在序列化要提交的表单时遇到了困难,这给我带来了很多问题。
这对我有用:
I think the user was asking about serializing, I was struggling serializing a form to submit and it was giving me a lot of issues.
This is what worked for me:
我用当前版本解决了这个问题: http://ajax. aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js
第 55 行之后 this.submit( function( event ) { - 我添加了这段代码:
I solved this problem with the current version: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js
After line 55 this.submit( function( event ) { - i added this code: