Add an FCKeditor with Javascript onlyAdd an FCKeditor with Javascript only

Posted July 12th, 2009 in FCKEditor and Javascript

I normally embed the FCKeditor HTML editor into my forms on the server-side using PHP but it's also possible to do using Javascript alone, as I worked out when writing last week's FCKEditor post about getting the word count when I needed to embed an example with Javascript.

Basic example

It's really quite simple, all you need to do is something like this:

<script type="text/javascript" src="/fckeditor/fckeditor.js"></script>
<script type="text/javascript">
    var oFCKeditor = new FCKeditor('FCKeditor1');
    oFCKeditor.BasePath = "/fckeditor/";
    oFCKeditor.Create();
</script>

Change /fckeditor/ in the Javascript src and BasePath to the correct path to your FCKEditor files.

Extended example

This extended example shows creating the editor with a number of various options set:

<script type="text/javascript" src="/fckeditor/fckeditor.js"></script>
<script type="text/javascript">
    var oFCKeditor = new FCKeditor('FCKeditor1');
    oFCKeditor.BasePath = "/fckeditor/";
    oFCKeditor.ToolbarSet = "Basic";
    oFCKeditor.Height = "500";
    oFCKeditor.Width = "500";
    oFCKeditor.Config["CustomConfigurationsPath"] = "/js/fckconfig.js";
    oFCKeditor.Config["EditorAreaCSS"] = "/css/fckeditor.css";
    oFCKeditor.Value = "<p>This is the initial text in the editor</p>";
    oFCKeditor.Create();
</script>

Related posts:

Share or Bookmark

Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.

Subscribe or Follow

Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

Comments

blog comments powered by Disqus