Change background color for ckEditor

I need to dynamically change the background color when loading using my ckEditor the page on which it is turned on is a page with dynamic loading, where the user has a certain bg color. I can not load css, it must be the background color of the editor background

so i tried

window.onload=function(){ CKEDITOR.instances.editor_data.addCss( 'body { background-color: #efefef; }' ); } 

I am not getting the error, but also not getting any changes

I also tried

 CKEDITOR.instances.editor_data.addCss( '#cke_editor_data { background-color: #efefef; }' ); 
+3
source share
1 answer

If you call this during window.load, then it's too late, addCss defines some css to load when creating the editor, but it does not change the executable instance.

So you can do it (using addCSS only):

 CKEDITOR.on('instanceCreated', function(e) { e.editor.addCss( 'body { background-color: red; }' ); }); 

Or this (a more general way of working with an edited document)

 CKEDITOR.on('instanceReady', function(e) { // First time e.editor.document.getBody().setStyle('background-color', 'blue'); // in case the user switches to source and back e.editor.on('contentDom', function() { e.editor.document.getBody().setStyle('background-color', 'blue'); }); }); 
+15
source

All Articles