Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

CKEDITOR - prevent adding image dimensions as a css style

How to prevent CKEDITOR from adding image dimensions as a style?

Instead of this:

<img src="image.jpg" style="height:100px; width:100px;">

I want this

<img src="image.jpg" height="100px" width="100px">
question from:https://stackoverflow.com/questions/2051896/ckeditor-prevent-adding-image-dimensions-as-a-css-style

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is one more way to do this (much simpler), by using Disallowed Content introduced in CKEditor 4.4.0:

CKEDITOR.replace( 'editor1', {
    disallowedContent : 'img{width,height}'
} );

or in config.js:

config.disallowedContent = 'img{width,height}';

This rule will disallow inline styles (width and height) for img element, CKEditor will use attributes instead.

If for some reason, you will notice that the width/height input elements in the Image dialog window are now gone, set the following as well:

config.extraAllowedContent = 'img[width,height]';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...