使用 jQuery 从 CKEditor 的 iframe 中抓取内容 [英] Using jQuery to grab the content from CKEditor's iframe

查看:29
本文介绍了使用 jQuery 从 CKEditor 的 iframe 中抓取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义编写的 CMS,它使用 CKEditor *(FCKEditor v3)用于编辑内容.我也在使用 jQuery 验证插件在基于 AJAX 的提交之前检查所有字段的错误.我正在使用 serialize() 函数来传递数据到 PHP 后端.

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.

问题是,序列化设法正确抓取所有字段,除了在 CKEditor 中键入的实际内容.与其他所有 WYSIWYG 编辑器一样,这个编辑器也将 iframe 覆盖在现有文本框上.而序列化忽略 iframe 并只查看文本框的内容,当然,它没有找到,因此返回一个空白的内容正文.

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.

我的方法是在 CKEditor 的 onchange 事件上创建一个钩子并同时更新文本框 (CKEDITOR.instances.[textboxname].getData() 返回内容)或其他一些隐藏字段,在编辑器中进行了任何更改.

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.

然而,由于 CKEditor 仍处于测试阶段并且严重缺乏文档,我找不到合适的 API 调用来使我能够这样做.

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?

推荐答案

另一个通用的解决方案是在您尝试提交表单时运行以下命令

Another generic solutions to this would be to run the following whenever you try to submit the form

for ( instance in CKEDITOR.instances )
            CKEDITOR.instances[instance].updateElement();

这将强制表单中的所有 CKEDITOR 实例更新它们各自的字段

This will force all CKEDITOR instances in the form to update their respective fields

这篇关于使用 jQuery 从 CKEditor 的 iframe 中抓取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆