insertHTML in CKEditor does not works only for images

I have tried to insert an uploaded image in to the CKEditor by using the following code,

var editor = CKEDITOR.instances.writearticle;
var value = '<img src="images/imagename.jpg">';
editor.insertHtml( value );

But this does not work. But when I try the same logic with this code

  • CKEditor and escaping elements
  • I can't add the Source button to CKEditor 4's toolbar
  • Does anyone know of a spell checker plugin for ckeditor that uses aspell or a similar local service instead of spellchecker.net?
  • CKEditor multiple editables with same selector?
  • How to hide and show a CKEditor using jQuery?
  • CKEditor - No toolbars
  • var editor = CKEDITOR.instances.writearticle;
    var value = '<strong>Hello World</strong>';
    editor.insertHtml( value );
    

    Hello world as bold text is inserted. Why it is not working for the <img> tag?

    I have found this procedure here and <img> insertion works in this site. What is the problem in my site?

  • <br/> tags is automatically getting added to html tags in ckeditor
  • Ckeditor selected html not working correct with chrome browser
  • Firefox allows desktop image files to be dragged in to CKEditor
  • CKEditor custom plugin surround selection with tag
  • Does anyone know of a spell checker plugin for ckeditor that uses aspell or a similar local service instead of spellchecker.net?
  • CKEditor 4: Keep cursor position after manually creating inline instance
  • 3 Solutions collect form web for “insertHTML in CKEditor does not works only for images”

    The problem was resolved after adding,

    config.allowedContent = 'img[src,alt,width,height]'; // But be sure to add all the other tags you use in with your Editor. Tags except this will be disabled.
    

    Alternate solution

    config.extraAllowedContent = 'img[src,alt,width,height]'

    This will add <img> attribute to the allowed tags list and here you need to to specify every tags you need to allow. – Credit: Sibbl.

    in the config.js file.

    In my case I just added:

    config.allowedContent = true;
    

    in the CKEditor configuration

    and it fixed the issue.

    You can also write allowedContent in here instead modify the config.

    editor.addCommand( 'XXXDialog', new CKEDITOR.dialogCommand( 'XXXDialog', { allowedContent : 'img[src,alt,width,height]'}) );