如何将@media打印样式应用于 ckeditor 实例

How can I apply a @media print style to a ckeditor instance?

本文关键字:应用于 ckeditor 实例 样式 打印 @media      更新时间:2023-09-26

我尝试在页面中定义@media样式以及我在配置中传递 ckeditor 的外部文件,但当我单击工具栏中的打印按钮时,似乎都没有任何效果。

这个例子(框架)应该给你一些想法(jsFiddle):

CKEDITOR.replace( 'editor', {
    plugins: 'toolbar,wysiwygarea,sourcearea,print,basicstyles',
    on: {
        // When CKEditor DOM is loaded, append stuff to <head>.
        contentDom: function() {
            var doc = this.document,
                head = doc.getHead();
            // Via <link> tag.
            doc.createElement( 'link', {
                attributes: {
                    rel: 'stylesheet',
                    type: 'text/css',
                    href: 'print.css',
                    media: 'print'
                }
            } ).appendTo( head );
            // Via <style> tag.
            var style = doc.createElement( 'style', {
                attributes: {
                    type: 'text/css'
                }
            } );
            style.setText( '@media print { * { color: red } }' );
            style.appendTo( head );
        }
    }
} );