访问iframe中的javascript ckeditor对象 [英] access javascript ckeditor object within an iframe

查看:252
本文介绍了访问iframe中的javascript ckeditor对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个iframe的页面,并且在iframe中有一个ckeditor实例,我想从包含的页面中销毁。

Lets say I have a page with an iframe and within the iframe I have a ckeditor instance that I want to destroy from the containing page.

我通常会尝试像这样:

var iframe_document = document.getElementById("iframe_id").contentWindow.document;
for(var i in iframe_document.CKEDITOR.instances)
  iframe_document.CKEDITOR.instances[i].destroy();

但是看起来ckeditor实例不能以这种方式访问​​。

However it appears that the ckeditor instance can not be accessed this way. Is it possible to destroy the instance from outside the document similar to this?

为了澄清确切的错误是无法读取未定义的属性实例

To clarify the exact error is "cannot read property 'instances' of undefined"

推荐答案

全局变量属于窗口,而不是文档,请尝试:

Global variables belong to the window, not to the document so try this:

var iframe_CKEDITOR = document.getElemenyById("iframe_id").contentWindow.CKEDITOR;
for(var i in iframe_CKEDITOR.instances)
  iframe_CKEDITOR.instances[i].destroy();

这篇关于访问iframe中的javascript ckeditor对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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