FCKeditor提供了一个完整的JavaScript API

FCKeditor offers a complete JavaScript API so you can interact with it once the editor is loaded and running.
FCKeditor提供了一个完整的JavaScript API(Application Public Interface),你可以利用这些API来处理FCK编辑器,只要它被加载完成或在正在运行中.
Retrieving an editor instanceOnce 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). When placing the editor in the page, you give it an "instance name". So, to retrieve it, you must simply call the FCKeditorAPI.GetInstance method.
一旦编辑器实例化完成后,它都会注册一个全局的对象,叫作FCKeditorAPI. 这个对象提供一个接入点去获取在本页面内的任何已实例化的对象(不止一个).当你在页面生成一个编辑器时,你给了它一个实例名.所以,你只需简单地调用 FCKeditorAPI.GetInstance方法就可以获取到它的对象引用.
For example: var oEditor = FCKeditorAPI.GetInstance('InstanceName') ;
例如,var oEditor = FCKeditorAPI.GetInstance('InstanceName') ; 这里就是获取实例名为"InstanceName"的FCKeditor对象.
The GetInstance method returns the main FCKeditor object that gives the necessary bridge to interact with it.
This is a list of properties and methods of this object:
这是一个FCKeditor的属性和方法的列表:


代码如下:

* Description = string 描述
* EditMode = Integer 编辑状态
* Name = string 名字
* Status = Integer 状态
* function AttachToOnSelectionChange(functionPointer)
* function CleanAndPaste(html)
* function CreateElement(tag)
* function CreateLink(url)
* function ExecOnSelectionChange() //Fires OnSelectionChange event in event manager
* function ExecOnSelectionChangeTimer()
* function ExecuteNamedCommand(commandName, commandParameter)
* function ExecuteRedirectedNamedCommand(commandName, commandParameter)
* function Focus()
* function GetHTML(format) // doesnt work. Use GetXHTML instead.
* function GetNamedCommandState(commandName)
* function GetNamedCommandValue(commandName)
* function GetXHTML(format)
* function InitializeBehaviors()
* function InsertElement(element)
* function InsertElementAndGetIt(e)
* function InsertHtml(html)
* function IsDirty();
* function MakeEditable()
* function OnDoubleClick(element)
* function Paste()
* function PasteAsPlainText()
* function PasteFromWord()
* function Preview()
* function RegisterDoubleClickHandler(handlerFunction, tag)
* function ResetIsDirty();
* function SetHTML(html, forceWYSIWYG)
* function SetStatus()
* function ShowContextMenu(x, y)
* function SwitchEditMode()
* function UpdateLinkedField()

EventsOnce the editor loading is complete and it is ready to use (and interact with JavaScript), a standard function is called in the page that contains the editor, if the function is defined.
This function must be named "FCKeditor_OnComplete" and receives the related editor instance as the parameter. Using it, you can execute any initial code that makes the initial interaction with the editor.
This is a declaration example:
function FCKeditor_OnComplete( editorInstance ) {
alert( editorInstance.Name ) ; }
Apart the above standard event, every FCKeditor instance has a "Event" object that can be used to listen for events to be fired.
For example, the following code listens for the "OnSelectionChange" to execute custom code:
var counter = 0 ;
function DoSomething( editorInstance ) {
window.document.title = editorInstance.Name + ' : ' + ( ++counter ) ; }
function FCKeditor_OnComplete( editorInstance ) {
editorInstance.Events.AttachEvent( 'OnSelectionChange', DoSomething ) ; }
Note that every callback function receives the editor instance as a parameter.
The following is the list of events available:
OnSelectionChange: fired when the actual selection in the editor area changes (by selection I mean the cursor position too... it changes on key strokes). Note: In IE6, this event does not fire on every keystroke, but only on some random keystrokes. Handy!
OnAfterSetHTML: fired once the HTML is loaded in the editor (including when changing views).
OnStatusChange: fired when the editor status changes. The following constants are also available globally in the page: FCK_STATUS_NOTLOADED, FCK_STATUS_ACTIVE and FCK_STATUS_COMPLETE.
OnPaste: fired when something is pasted in the editor
配置选项:
AutoDetectLanguage=true/false 自动检测语言
BaseHref="" _fcksavedurl="""" 相对链接的基地址
ContentLangDirection="ltr/rtl" 默认文字方向
ContextMenu=字符串数组,右键菜单的内容
CustomConfigurationsPath="" 自定义配置文件路径和名称
Debug=true/false 是否开启调试功能,这样,当调用FCKDebug.Output()时,会在调试窗中输出内容
DefaultLanguage="" 缺省语言
EditorAreaCss="" 编辑区的样式表文件
EnableSourceXHTML=true/false 为TRUE时,当由可视化界面切换到代码页时,把HTML处理成XHTML
EnableXHTML=true/false 是否允许使用XHTML取代HTML
FillEmptyBlocks=true/false 使用这个功能,可以将空的块级元素用空格来替代
FontColors="" 设置显示颜色拾取器时文字颜色列表
FontFormats="" 设置显示在文字格式列表中的命名
FontNames="" 字体列表中的字体名
FontSizes="" 字体大小中的字号列表
ForcePasteAsPlainText=true/false 强制粘贴为纯文本
ForceSimpleAmpersand=true/false 是否不把&符号转换为XML实体
FormatIndentator="" 当在源码格式下缩进代码使用的字符
FormatOutput=true/false 当输出内容时是否自动格式化代码
FormatSource=true/false 在切换到代码视图时是否自动格式化代码
FullPage=true/false 是否允许编辑整个HTML文件,还是仅允许编辑BODY间的内容
GeckoUseSPAN=true/false 是否允许SPAN标记代替B,I,U标记
IeSpellDownloadUrl=""下载拼写检查器的网址
ImageBrowser=true/false 是否允许浏览服务器功能
ImageBrowserURL="" 浏览服务器时运行的URL
ImageBrowserWindowHeight="" 图像浏览器窗口高度
ImageBrowserWindowWidth="" 图像浏览器窗口宽度
LinkBrowser=true/false 是否允许在插入链接时浏览服务器
LinkBrowserURL="" 插入链接时浏览服务器的URL
LinkBrowserWindowHeight=""链接目标浏览器窗口高度
LinkBrowserWindowWidth=""链接目标浏览器窗口宽度
Plugins=object 注册插件
PluginsPath="" 插件文件夹
ShowBorders=true/false 合并边框
SkinPath="" 皮肤文件夹位置
SmileyColumns=12 图符窗列数
SmileyImages=字符数组 图符窗中图片文件名数组
SmileyPath="" 图符文件夹路径
SmileyWindowHeight 图符窗口高度
SmileyWindowWidth 图符窗口宽度
SpellChecker="ieSpell/Spellerpages" 设置拼写检查器
StartupFocus=true/false 开启时FOCUS到编辑器
StylesXmlPath="" 设置定义CSS样式列表的XML文件的位置
TabSpaces=4 TAB键产生的空格字符数
ToolBarCanCollapse=true/false 是否允许展开/折叠工具栏
ToolbarSets=object 允许使用TOOLBAR集合
ToolbarStartExpanded=true/false 开启是TOOLBAR是否展开
UseBROnCarriageReturn=true/false 当回车时是产生BR标记还是P或者DIV标记

(0)

相关推荐

  • FCKEditor常用Js代码,获取FCK内容,统计FCK字数,向FCK写入指定代码

    content相当于你例子中的FCKeditor1. 复制代码 代码如下: //获取格式化的编辑器内容 function getEditorContents(){ var oEditor = FCKeditorAPI.GetInstance("content"); alert(oEditor.GetXHTML(true)); } //向编辑器插入指定代码 function insertHTMLToEditor(codeStr){ var oEditor = FCKeditorAPI.G

  • javascript 获取FCKeditor内容

    形式如: 复制代码 代码如下: varoEditor=FCKeditorAPI.GetInstance('content'); varcontent=oEditor.GetXHTML(true); ************************************************* 利用Javascript取和设FCKeditor值也是非常容易的,如下: 复制代码 代码如下: // 获取编辑器中HTML内容 function getEditorHTMLContents(Editor

  • extjs fckeditor集成代码

    复制代码 代码如下: { xtype : "textarea", name : "content", anchor : '97%', height : 400, id : "content", fieldLabel : "内容", listeners : { "render" : function(f) { fckEditor = new FCKeditor("content"); fc

  • JS集成fckeditor及判断内容是否为空的方法

    本文实例讲述了JS集成fckeditor及判断内容是否为空的方法.分享给大家供大家参考,具体如下: <script type="text/javascript"> <!-- // Automatically calculates the editor base path based on the _samples directory. // This is usefull only for these samples. A real application shoul

  • javascript fckeditor编辑器取值与赋值实现代码

    获取编辑器中HTML内容 复制代码 代码如下: function getEditorHTMLContents(EditorName) { var oEditor = FCKeditorAPI.GetInstance(EditorName); return(oEditor.GetXHTML(true)); } 获取编辑器中文字内容 复制代码 代码如下: function getEditorTextContents(EditorName) { var oEditor = FCKeditorAPI.G

  • js判断FCKeditor内容是否为空的两种形式

    形式1: 复制代码 代码如下: function checkFCK(key) { var oEditor=FCKeditorAPI.GetInstance(key); var content=oEditor.GetXHTML(true); content=content.replace(/ /g,""); content=content.replace(/\s/g,""); content=content.replace(/ /g,""); co

  • fckeditor常用Js,获取fckeditor内容,统计fckeditor字数,向fckeditor写入指定代码

    content相当于你例子中的FCKeditor1. 复制代码 代码如下: //获取格式化的编辑器内容 function getEditorContents(){ var oEditor = FCKeditorAPI.GetInstance("content"); alert(oEditor.GetXHTML(true)); } //向编辑器插入指定代码 function insertHTMLToEditor(codeStr){ var oEditor = FCKeditorAPI.G

  • jsp fckeditor 上传中文图片乱码问题的解决方法

    经过我修改ConnectorServlet.java和SimpleUploaderServlet.java两个文件,重新生成fckeditor-java-2.3.jar包,要解决所有的乱码问题,有3部要修改1.修改Web容器的字符编码,如果Web容器用的是Tomcat,则修改conf/server.xml文件,在两个Connector中添加"URIEncoding="utf-8"",我这里用的是utf-8编码,所以修改成utf-8,若项目是gb2312编码,则设置为

  • Js FCKeditor的值获取和修改的代码小结

    利用Javascript取和设FCKeditor值也是非常容易的,如下: // 获取编辑器中HTML内容 function getEditorHTMLContents(EditorName) { var oEditor = FCKeditorAPI.GetInstance(EditorName); return(oEditor.GetXHTML(true)); } // 获取编辑器中文字内容 function getEditorTextContents(EditorName) { var oEd

  • FCKeditorAPI 手册 js操作获取等

    复制代码 代码如下: function abc() { var checkContent =FCKeditorAPI.GetInstance("editor");//获取实例 alert(checkContent.GetXHTML());//获取当前内容 var newelement = document.createElement("a"); newelement.href="#"; newelement.innerHTML="df&

  • JSP 页面中使用FCKeditor控件(js用法)

    它可和PHP.JavaScript.ASP.ASP.NET.ColdFusion.Java.以及ABAP等不同的编程语言相结合."FCKeditor"名称中的"FCK" 是这个编辑器的作者的名字Frederico Caldeira Knabben的缩写. FCKeditor控件请到官方网站下载http://www.fckeditor.net,本例主要用到FCKeditor_2.6.3.zip.fckeditor-java-demo-2.4.1.zip.fckedit

随机推荐