如何动态改变tinymce编辑器字体的样式和大小?

时间:2012-08-13 15:12:33

标签: tinymce

tinymce FAQ explains如何通过引用自定义content_css文件来更改编辑器的默认字体样式。

但我想以编程方式动态更改编辑器的字体样式。有任何想法吗?感谢。

1 个答案:

答案 0 :(得分:0)

这是可能的,但需要一些知识。

您需要调用类似

的内容
self.switchStyle(url, ed);

其中switchStyle是

    // url is the url to the stylesheet file to be added to the editor iframes head
    // ed is the editor object or editor id
    switchStyle: function(url, ed) {

        if (typeof ed != 'object') {
            ed = tinymce.get(ed);
        }

                    //replace the custom content_css if set
        var url_to_replace = ed.getParam('content_css');

        var doc = ed.getDoc();
        var $doc = $(doc);

        var sheets_urls = [];

        if (url_to_replace){
            sheets_urls.push(url_to_replace);
        }

        // remove all stylesheets from sheets_urls
        $doc.find('link').each(function() {
            if (tinymce.inArray(sheets_urls, $(this).attr('href').split('?')[0]) !== -1) {
                $(this).remove();
            }
        });

        var link  = doc.createElement('link');
        link.type = 'text/css';
        link.rel  = 'stylesheet';
        link.href = url;

        // setstylesheet
        $doc.find('head:first').append(link);
    },
相关问题