---
title: "CKEditor And Box window Note"
author: "myrev"
date: "2010-08-29T14:59:15Z"
tags: ["Cache", "Chrome", "Firefox"]
categories: ["编程语言"]
slug: "ckeditor-and-box-window-note"
draft: false
lastmod: "2010-08-29T14:59:35Z"
id: 750088
url: "https://myrev.iteye.com/blog/750088"
---

# C KEditor And Box window Note

1 . open a new page

if( CKEDITOR.instances\[element\_id] )

\# it will delete the CKEDITOR old instance from cache but it won't  remove the CKEDITOR DOM

(Because the new page has no CKEDITOR DOM, so we needn't destroy it, just use remove. If you use destroy method, it will produce a bug! )

CKEDITOR.remove(CKEDITOR.instances\[element\_id]) ;

CKEDITOR.replace(element\_id, options)

2\. create a ckeditor and destroy it in one page

CKEDITOR.replace(element\_id, options)

CK EDITOR .instances\[element\_id]) .destroy() # it will remove the CKEDITOR DOM

3\. In Chrome

When you use ckeditor in chrome, you should remember create ckeditor after box resized.

1\) create a ckedtior in a new popup window

you should run the create ckeditor code on popup window event : on\_complete

CK\_Reload = function() {if (CKEDITOR.instances\['#{element\_id}']) {  
        CKEDITOR.remove(CKEDITOR.instances\['#{element\_id}']);}  
        CKEDITOR.replace('#{element\_id}', { #{ckeditor\_applay\_options(ckeditor\_options)} });return '#{element\_id}';}

I run CK\_Reload in on\_complete event.

2\) re-create a ckeditor in popup window

you should run the re-create ckeditor code after popup window resized.

_ error.js.erb

var content = '';  
var element\_id = '';  
for (instance in CKEDITOR.instances){  
  element\_id = instance;  
  content = $('#'+instance).val(); //get old data  
}  
$.colorbox.resize();  
CKEDITOR.instances\[element\_id].destroy();  
CKEDITOR.replace(element\_id, &lt;%=load\_ckeditor\_options %&gt;);  
CKEDITOR.instances\[element\_id].setData(content);

3\) If you use box resize method:

- you can't edit ckeditor. You should re-create a new ckeditor or you use CKEDITOR.instances\[element\_id].setData(old\_data) .

<!--THE END-->

- If you want to ckeditor use textarea value, you should re-create a new ckeditor before resize.

<!--THE END-->

- If you resize the box window,  a new cked itor can't get data from textarea.

<!--THE END-->

- Or you can use CKEDITOR.instances\[eleme nt\_id].setData(content) to set ckeditor value after resize.

<!--THE END-->

4\. In firefox

1\) If you use box resize method:

- you can use ckeditor
- If you want to ckeditor use textarea value, you should re-create a new ckeditor before resize.
- If you resize the box window,  a new ckeditor can't get data from textarea.
- Or you can use CKEDITOR.instances\[element\_id].setData(content) to set ckeditor value after resize.