setting external css to ck editor dynamically in djbrowser

旧巷老猫 提交于 2019-12-13 03:58:59

问题


i embedded ck editor (recent version 4.1) into dj browswer. dj browser

and i want to set a external css file (http://mystyle.css) into the ck editor.

but i do not want to modify or edit config files of ck editor. the url of css should be set dynamically, on the run time and its name and url can be changed.

what i tried is invoking the following command, but did not help.

CKEDITOR.stylesSet.add('mystyle');
..
CKEDITOR.config.stylesSet('mystyle:http://mystyle.css');

回答1:


They key is to access the document object of the CKE iframe. Then you just vomit a CSS link to the head of the document without touching the config. Example is from https://stackoverflow.com/a/577002/694325

I am assuming that you use "editor1" for the name, but use whatever you have..

var doc = CKEDITOR.instances.editor1.document.$; // get CKE doc!
var cssId = 'myCss';
if (!doc.getElementById(cssId))
{
    var head  = doc.getElementsByTagName('head')[0];
    var link  = doc.createElement('link');
    link.id   = cssId;
    link.rel  = 'stylesheet';
    link.type = 'text/css';
    link.href = 'http://my.little.pony.net/Your.css';
    link.media = 'all';
    head.appendChild(link);
}

Or you could jQuery it if you are into that kind of stuff (https://stackoverflow.com/a/2685661/694325)

var doc = CKEDITOR.instances.editor1.document.$; // shortcut
$("<link/>", {
   rel: "stylesheet",
   type: "text/css",
   href: "http://my.little.pony.net/Your.css"
}).appendTo($(doc).find("head"));


来源:https://stackoverflow.com/questions/16081472/setting-external-css-to-ck-editor-dynamically-in-djbrowser

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