Viswalinga Surya S Viswalinga Surya S - 2 years ago 193
Javascript Question

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

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

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download