Getting a handle to an FCKEditor Editor Instance
Posted March 17th, 2009 in FCKEditor
FCKEditor is an in-browser WYSIWYG HTML editor written in Javascript. There are times when you need to interact with the FCKEditor API; in order to use the API you need to first get a handle to the instance of the editor. This post shows how to do this; I have posted this code previously as part of another post but need to easily find it so have dedicated it to its own post.
If the instance name of the FCKEditor was 'html' then you can get a handle in Javascript like so:
var oEditor = FCKeditorAPI.GetInstance('html');
At that stage you can call any of the API functions, assign event handlers etc to the oEditor variable.
For example, to insert some HTML at the current insertion point (or overwrite the existing HTML if some is selected) you can call the InsertHtml function like so:
oEditor.InsertHtml("<p>hello world</p>");
A full list of the API functions can be found in the FCKeditor Javascript API documentation.
If the Javascript code is being run from a popup window, then you can get a handle to the instance in the parent window like this:
var oEditor = window.opener.FCKeditorAPI.GetInstance('html');
I post an FCKEditor post in the Javascript section of this blog roughly every 10 days, and will look at some of the API functions in detail over the next few posts. Be sure to subscribe to my RSS feed (details below) so you don't miss out.
Related posts:
- Get the HTML from an FCKEditor instance (Sunday, March 29th 2009)
- Insert HTML into FCKEditor (Friday, February 13th 2009)
- Using the FCKEditor HTML Editor with PHP (Wednesday, August 20th 2008)
Subscribe / Follow / Email / Bookmark / Share
Use the buttons below to subscribe to my RSS feed to be notified next time something is posted, share this post with others, or subscribe by email to have my posts sent in a daily email, follow me on Twitter or follow me on Facebook.
At least one new post is usually made every day. See my posting schedule for more details.
