Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not show content in CKeditor after the second time

In my project, the Ckeditor is part of a webpage, which is coded using GWT. So the interface to CKeditor is using Java.

Whenever the webpage is displayed, the CKeditor will be passed a HTML via setData(), which the CKeditor is supposed to show.

The problem is: CKeditor sometimes won't show the HTML. Its content was just empty, although I am very sure the html had been passed to setData().

I had tried several approaches to solve this problem, but none would work.

My approach

  • Create a TextArea using DOM.createTextArea()
  • Call myEditor=CKEDITOR.replace(textArea, config) to initialize the CKeditor
  • call myEditor.setData(html) to set the content.

It was good and showed the content at the first time.

But after the webpage got hidden and shown again, I called myEditor.setData(html2) to show another html, but this time the CKeditor showed nothing.

First solution (did not work)

I changed the code to call myEditor.destroy() before the webpage was hidden, and call CKEDITOR.replace(textArea, config) again when the webpage was visible again, after that I called myEditor.setData(newHtml).

This time it worked in IE and FF, but not in Chrome and Edge, it kept showing the content of the first load time, instead of showing the new HTML.

Second solution (did not work)

I changed it to call CKEDITOR.inline(textArea, config) instead of CKEDITOR.replace(textArea, config) when the webpage was visible again, while the destroy() and setData() was still called in the same order. This time the CKeditor again didn't show anything from the second time.

Last attempt

My last approach was to not calling destroy(), but creating a new TextArea each time before showing CKeditor, and called CKEDITOR.replace(textArea, config) and setData(html). This seems to work well, but occasionally the CKeditor still showed empty content.

Could anyone please help me to solve this problem?

I am using CKeditor 4.5.8.

like image 522
Jamie Liu Avatar asked Dec 05 '25 07:12

Jamie Liu


1 Answers

Finally I figured out the solution:

Before hiding the ckeditor, call editor.destroy(true), and delete editor. (Before this, I only called editor.destroy() [note: no 'true'], which didn't work well).

Here is the code:

    if (editor) {
        editor.destroy(true);
        delete editor;
    }
like image 151
Jamie Liu Avatar answered Dec 09 '25 14:12

Jamie Liu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!