简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM