使用FCKeditorAPI与fckeditor交互

使用FCKeditorAPI与fckeditor交互
作者:zccst

1,获取name值,

FCKeditorAPI.GetInstance('yourtextareaname').GetHTML(); //整个dom
FCKeditorAPI.GetInstance('yourtextareaname').GetXHTML(); //带标签

也可以
FCKeditorAPI.Instances.yourtextareaname.GetXHTML(html);

GetHTML( formatted ), or GetXHTML( formatted ), or GetData( formatted )
- retrieves the edited html from the editor.
获取编辑器中的html内容,其中oEditor.GetXHTML(formatted); // formatted 为:true|false,表示是否按HTML格式取出


2,设置name值
FCKeditorAPI.Instances.yourtextareaname.SetHTML(html);
追加插入name值
FCKeditorAPI.Instances.yourtextareaname.InsertHtml(html);


批注:其实弄清楚如何使用,最好的办法是查看dom。因为一旦fckeditor加载成功,则会显示其dom对象,及子对象,还有他们的方法。


附:官方资料
FCKeditor JavaScript API

地址:http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/JavaScript_API


FCKeditor offers a complete JavaScript API so you can interact with it once the editor is loaded and running.

Once loaded, the editor registers a global object called FCKeditorAPI. This object offers the entry point to

interact with any editor instance placed in a page (you can have more than one).

NOTE: The FCKeditorAPI object will not be available during the page load. You need to wait for the editor to

be loaded to use it. If you need to interact with the editor right after is has been loaded, use the

"FCKeditor_OnComplete" function (see Events).

Retrieving an Editor Instance

From out of an external script
When placing the editor in the page, you give it an "instance name". To retrieve it, you must simply call the FCKeditorAPI.GetInstance method.
Example:

var oEditor = FCKeditorAPI.GetInstance('InstanceName') ;

From out of a dialog of the editor
Call the InnerDialogLoaded to get the FCKObject.
Example:

var oEditor = window.parent.InnerDialogLoaded().FCK ;

Both methods return the main FCKeditor object that gives the necessary bridge to interact with it. These are the most useful properties and methods of this object:

Properties:

Name = ( string ) - the instance name.
Status = ( integer ) - the editor status (loading status).
EditorDocument = ( object ) - the DOM Document object for the editing area.
EditorWindow = ( object ) - the DOM Window object for the editing area.

Methods:

AttachToOnSelectionChange( functionPointer )
Focus()
SetHTML( html ), or SetData( html ) - sets the contents of the editor. Note that when using this method, you will loose any listener that you may have previously registered on the editor.EditorDocument.
GetHTML( formatted ), or GetXHTML( formatted ), or GetData( formatted ) - retrieves the edited html from the editor.
InsertElement( element )
InsertElementAndGetIt( e )
InsertHtml( html ) - inserts HTML in the current cursor position
IsDirty() - checks if the content in the editor has been changed
MakeEditable()
ResetIsDirty() - resets the dirty state
SwitchEditMode()
UpdateLinkedField()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值