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

最后都变了- 提交于 2019-12-10 11:14:38

问题


I have tried defining a @media style in the page as well as the external file that I am passing ckeditor in the config but neither seems to have any effect when I click the print button in the toolbar.


回答1:


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 );
        }
    }
} );


来源:https://stackoverflow.com/questions/19230376/how-can-i-apply-a-media-print-style-to-a-ckeditor-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!