0

I am trying to add a css file dynamically to the ckeditor. The css file is uploaded using an uploader on the same page as the editor and oncomplete I want to add the css file to the ckeditor using the below code,

function addToEditor(editorName, fileUrl)
if(fileUrl != '')
    {
        var randomNumber = Math.random();

        alert(_gWebDocRoot + fileUrl + '?v='+ randomNumber);

        CKEDITOR.instances[editorName].config.contentsCss = _gWebDocRoot + fileUrl + '?v='+ randomNumber;
    }
}

But the above code does not work, please help me solve this issue. Regards,

Neha

Neha Dangui
  • 597
  • 2
  • 13
  • 28
  • Please add this in jsfiddle. – Kushal Vora Oct 10 '15 at 09:37
  • Possible duplicate of [setting external css to ck editor dynamically in djbrowser](http://stackoverflow.com/questions/16081472/setting-external-css-to-ck-editor-dynamically-in-djbrowser) – Krease Jan 01 '16 at 08:06

1 Answers1

-3
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"));
Kushal Vora
  • 342
  • 2
  • 16
  • @ᴀʀᴛᴜʀғɪʟɪᴘɪᴀᴋ, Doesn't matter about the copy paste. Solution should be work. – Kushal Vora Oct 10 '15 at 09:44
  • 2
    Yes, it does matter. Flag the question as a *duplicate* if it has been already answered elsewhere. – Artur Filipiak Oct 10 '15 at 09:47
  • I tried the below code, var doc = CKEDITOR.instances.editorName.document.$; // shortcut $("", { rel: "stylesheet", type: "text/css", href: _gWebDocRoot + fileUrl + '?v='+ randomNumber }).appendTo($(doc).find("head")); But it does not work. Gives the below error, CKEDITOR.instances.editorName is undefined – Neha Dangui Oct 10 '15 at 09:49
  • Change some editor name. In your case you are passing dynamically. Something like CKEDITOR.instances[editorName] – Kushal Vora Oct 10 '15 at 09:53
  • I tried this, var doc = CKEDITOR.instances[editorName].document.$; also var doc = CKEDITOR.instances[editorName]; Does not give error but does not add the css file to the editor also. – Neha Dangui Oct 10 '15 at 09:55