0

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"

2
  • Is the iframe content coming from the domain of the website the script is running in? Commented Sep 25, 2012 at 22:50
  • @Eric Yes, it is a page meant to be viewed on its own outside of the iframe as well however. Commented Sep 25, 2012 at 22:51

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

2 Comments

Wow. Thanks. If only you had answered earlier, i fumbled with this for hours and finally just overloaded the save button on the editor itself. If only i had known the solution was so simple! Looks like I have lots to learn about Javascript still.
In case of problems you should always use a proper js debugger like Firebug, that way you can see what are the objects that you have instead of doing guess work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.