changing the background color for ckEditor

前端 未结 1 499
情歌与酒
情歌与酒 2021-01-13 23:15

I need to change the background color dynamically on load with my ckEditor the page that it is on is a dynamically loading page where they user has a specific bg color. I ca

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 23:52

    If you're calling that during window.load then it's too late, addCss defines some css to load when the editor is created, but it doesn't modify the running instance.

    So you can so this (using only addCSS):

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

    Or this (a more generic way to work with the 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');
        });
    });
    

    0 讨论(0)
提交回复
热议问题