如何将@media打印样式应用于ckeditor实例? [英] How can I apply a @media print style to a ckeditor instance?

查看:394
本文介绍了如何将@media打印样式应用于ckeditor实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试在页面中定义一个 @media 样式,以及我在配置中传递ckeditor的外部文件,但似乎没有任何效果,当我

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.

推荐答案

此示例(框架)应该提供一些想法( jsFiddle ):

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

这篇关于如何将@media打印样式应用于ckeditor实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆