access javascript ckeditor object within an iframe

最后都变了- 提交于 2020-01-17 02:20:13

问题


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.

I would usually try something like this:

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

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"


回答1:


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();


来源:https://stackoverflow.com/questions/12591587/access-javascript-ckeditor-object-within-an-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!