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

╄→гoц情女王★ 提交于 2019-12-06 12:55:50

This example (framed) should give you some ideas (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 );
        }
    }
} );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!