FCKEditor - how to access the HTML content from JavaScript?

Imagine you have a form in which you use FCKEditor as an inline HTML editor. So, inside script tag you have this:

var oFCKeditor = new FCKeditor('body_html');
oFCKeditor.BasePath = "A_PATH_TO_FCKEDITOR";
oFCKeditor.ToolbarSet = "Basic";
oFCKeditor.Create();

As you know, this creates a textarea with id set to ‘body_html’ and make it look like an inline HTML editor.

Going forward, you would like to receive the HTML code that represents the content of this textarea, and that you want to do this in JavaScript. In order to do that you need to follow FCKEditor API, so do somethink like this:

FCKeditorAPI.GetInstance('body_html').GetHTML(true);

Maybe it’s obvious but it took my a while to find out how to do this…

5 Responses to “FCKEditor - how to access the HTML content from JavaScript?”


  1. 1 Bernie Wiemers

    Thank you so much for publishing this post.

    I’ve had the same problem and spent hours trying to find a solution without success.

    I read your post, tried out what you said, and it worked!

    Thank you

  2. 2 Rob Wagner

    Sir,

    Thanks for the sample; however it only works for an alert; e.g.

    If I attempt to assign the output of getHTML to a JS variable, I get the error, Object doesn’t support this property or method.

    Thoughts?

    Thanks!
    Robert in Vermont

  3. 3 Jarosław Dobrzański
  4. 4 Rob Wagner

    Jarek,

    Good reading, but it turned out to be my misuse of the FCKEditor JS API. It should have been:

    FCKeditorAPI.GetInstance(’body_html’).GetHTML(false);

    …instead of:

    FCKeditorAPI.GetInstance(’body_html’).GetHTML(true);

    The documentation for this API doesn’t really explain the function of that parameter.

    Over this mountain and on to the next !

    Cheers,
    Rob

  5. 5 sohail

    Thanks for your opinion, but my dear it doesn’t work with HTML values…….

Leave a Reply