| 1 | <html> |
|---|
| 2 | <body> |
|---|
| 3 | <script> |
|---|
| 4 | function toggle() { |
|---|
| 5 | var editor = !!window['CKEDITOR'] && CKEDITOR.instances.editor; |
|---|
| 6 | if (!editor) { |
|---|
| 7 | loadScript('ckeditor/ckeditor.js', function() { |
|---|
| 8 | CKEDITOR.config.height = 150; |
|---|
| 9 | CKEDITOR.config.width = 'auto'; |
|---|
| 10 | CKEDITOR.replace( 'editor' ) |
|---|
| 11 | setTimeout(function() { |
|---|
| 12 | CKEDITOR.instances.editor.destroy(); |
|---|
| 13 | },0); |
|---|
| 14 | }); |
|---|
| 15 | } |
|---|
| 16 | } |
|---|
| 17 | function loadScript(url, callback){ |
|---|
| 18 | |
|---|
| 19 | var script = document.createElement("script") |
|---|
| 20 | script.type = "text/javascript"; |
|---|
| 21 | |
|---|
| 22 | if (script.readyState){ //IE |
|---|
| 23 | script.onreadystatechange = function(){ |
|---|
| 24 | if (script.readyState == "loaded" || |
|---|
| 25 | script.readyState == "complete"){ |
|---|
| 26 | script.onreadystatechange = null; |
|---|
| 27 | callback(); |
|---|
| 28 | } |
|---|
| 29 | }; |
|---|
| 30 | } else { //Others |
|---|
| 31 | script.onload = function(){ |
|---|
| 32 | callback(); |
|---|
| 33 | }; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | script.src = url; |
|---|
| 37 | document.getElementsByTagName("head")[0].appendChild(script); |
|---|
| 38 | } |
|---|
| 39 | </script> |
|---|
| 40 | <button type="button" onclick="toggle()">Load/Destory</button> |
|---|
| 41 | <div id="editor"></div> |
|---|
| 42 | </body> |
|---|
| 43 | </html> |
|---|