論壇目錄 / 程式設計 / 網頁/網站程式 / JavaScript /

從外部編輯 FCKEditor 的內容

發表新主題
隨機主題
上個主題
下個主題
|
    從外部編輯 FCKEditor 的內容

    ???有些功能是自己想追加的,修改 FCKeditor 源碼又不是那麼的容易,所以都一直找不到合適的方法,今天總算找到了,鳴~淚奔

    原來在 fckeditor 裡面編輯內容,是透過 fckeditor 外面的 button 來增加 fckeditor 編輯區的內容,也就是說在 fckeditor 外面有個 button,按下 button 就會 insert 一段 HTML。

    所以就使用我們用來控制 Fckeditor 物件。

    像是這樣
    oFckeditor=FCKeditorAPI.GetInstance('InstanceName');

    接著就可以用 InsertHtml 來增加一些 HTML
    oFckeditor.InsertHtml('<div>外部加入的 HTML!!</div>');

    另外還有控制 Fckeditor 捲軸的方法
    EditorWindow.scrollTo(0,oFckeditor.EditorDocument.body.scrollHeight);

    oFckeditor.EditorWindow 是 Fckeditor 裡面的 window
    oFckeditor.EditorDocument 是 Fckeditor 裡面的 document
    因此,一般 window 和 document 物件可以做到的,EditorWindow 和 EditorDocument 應該都可以做到唷 。

    • 關鍵字 : oFckeditor, fckeditor, Fckeditor, button, EditorWindow, EditorDocument, window, document, InsertHtml, 物件可以做到, 可以做到唷, 來增加一些, 一直找不到合適, scrollTo, scrollHeight, insert, InstanceName, GetInstance, FCKeditorAPI, FCKeditor
    00
    2009-03-18T07:45:14+0000
    ???FCKeditorApi

    最詳細的FCKeditorApi文檔默過於官方wiki提供的文檔了。

    FCKeditorApi官方文檔地址:http://wiki.fckeditor.net/Developer's_Guide/Javascript_API

    下面提供國內某網友的翻譯文檔,轉載地址:http://blog.imwebs.com/article.asp?id=322

    FCK編輯器加載後,將會注冊一個全局的FCKeditorAPI對象。

    FCKeditorAPI對象在頁面加載期間是無效的,直到頁面加載完成。如果需要交互式地知道FCK編輯器已經加載完成,可使用"FCKeditor_OnComplete"函數。

    <scripttype="text/javascript">
    functionFCKeditor_OnComplete(editorInstance){
    FCKeditorAPI.GetInstance('FCKeditor1').Commands.GetCommand('FitWindow').Execute();
    }
    </script>

    在當前頁獲得FCK編輯器實例:
    varEditor=FCKeditorAPI.GetInstance('InstanceName');

    從FCK編輯器的彈出窗口中獲得FCK編輯器實例:
    varEditor=window.parent.InnerDialogLoaded().FCK;

    從框架頁面的子框架中獲得其它子框架的FCK編輯器實例:
    varEditor=window.FrameName.FCKeditorAPI.GetInstance('InstanceName');

    從頁面彈出窗口中獲得父窗口的FCK編輯器實例:
    varEditor=opener.FCKeditorAPI.GetInstance('InstanceName');

    獲得FCK編輯器的內容:
    oEditor.GetXHTML(formatted);//formatted為:true|false,表示是否按HTML格式取出

    也可用:
    oEditor.GetXHTML();

    設置FCK編輯器的內容:
    oEditor.SetHTML("content",false);//第二個參數為:true|false,是否以所見即所得方式設置其內容。此方法常用於"設置初始值"或"表單重置"哦作。

    插入內容到FCK編輯器:
    oEditor.InsertHtml("html");//"html"為HTML文本

    檢查FCK編輯器內容是否發生變化:
    oEditor.IsDirty();

    在FCK編輯器之外調用FCK編輯器工具條命令:

    命令列表如下:


    DocProps,Templates,Link,Unlink,Anchor,BulletedList,NumberedList,About,Find,Replace,Image,Flash,SpecialChar,Smiley,Table,TableProp,TableCellProp,UniversalKey,Style,FontName,FontSize,FontFormat,Source,Preview,Save,NewPage,PageBreak,TextColor,BGColor,PasteText,PasteWord,TableInsertRow,TableDeleteRows,TableInsertColumn,TableDeleteColumns,TableInsertCell,TableDeleteCells,TableMergeCells,TableSplitCell,TableDelete,Form,Checkbox,Radio,TextField,Textarea,HiddenField,Button,Select,ImageButton,SpellCheck,FitWindow,Undo,Redo


    使用方法如下:
    oEditor.Commands.GetCommand('FitWindow').Execute();

    00
    2009-09-10T19:04:55+0000


    • 當您未登入羊皮紙時,可以利用臉書 Facebook 登入來發表迴響。若使用羊皮紙會員身份發表迴響則可獲得經驗值及虛擬金幣,用來參加羊皮紙推出的活動。
    發表迴響
     
    驗證字串
    留言