4

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 <img> tag?

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

4

3 回答 3

3

添加后问题解决,

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.

替代解决方案

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

这会将<img>属性添加到允许的标签列表中,在这里您需要指定您需要允许的每个标签。-学分:西布尔

在 config.js 文件中。

于 2013-10-21T06:17:51.803 回答
1

就我而言,我刚刚添加了:

config.allowedContent = true;

在 CKEditor 配置中

它解决了这个问题。

于 2016-06-09T09:13:11.447 回答
0

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

editor.addCommand( 'XXXDialog', new CKEDITOR.dialogCommand( 'XXXDialog', { allowedContent : 'img[src,alt,width,height]'}) );
于 2014-09-12T06:52:21.353 回答