Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uncaught exception: [CKEDITOR.editor] The instance already exists

I've included the CKEditor on my site. Everything works even though I get this JS error:

uncaught exception: [CKEDITOR.editor] The instance "simple_editor" already exists.

The code below is contained inside a PHP file which I include where ever I want the editor. I only have one instance of the editor per page.

<textarea class='ckeditor' id='simple_editor' name='simple_editor'>".$page_content."</textarea>";

<script type="text/javascript">
 CKEDITOR.replace( 'simple_editor',
 { 
  height: '110px',
  toolbar :
  [
   ['Link','Unlink'],
   ['Styles','Format','Font','FontSize'],
   ['Bold','Italic','Underline','Strike'],
   ['TextColor','BGColor'],
   ['NumberedList','BulletedList','Outdent','Indent']
  ]
 }); 
</script>

After some googling I've seen people posting some solution which dosnt work.

if (CKEDITOR.instances['simple_editor']) { delete CKEDITOR.instances['simple_editor'] };
if (CKEDITOR.instances['simple_editor']) { CKEDITOR.instances['simple_editor'].destroy(); }

Anyone know what to do? :S

like image 697
horgen Avatar asked Aug 31 '10 07:08

horgen


2 Answers

remove class='ckeditor' as it's triggering the automatic replacement system.

like image 196
AlfonsoML Avatar answered Nov 13 '22 18:11

AlfonsoML


<textarea id="textarea1" name="textarea1" runat="server" ></textarea>
<script>

$(document).ready(function () {

            loadEditor('<%= textarea1.ClientID %>');
        });

        function loadEditor(id) {
            var instance = CKEDITOR.instances[id];
            if (instance) {
                CKEDITOR.remove(instance);
            }
            CKEDITOR.replace(id, { toolbar: 'Basic' });
        }

</script>
like image 3
Manish Avatar answered Nov 13 '22 19:11

Manish