FCK的進階功能和常見問題的解決方案

來源:互聯網
上載者:User

FCKeditor是一個專門使用在網頁上屬於開放原始碼的所見即所得 (WYSIWYG)文字編輯器。它志於輕量化,不需要太複雜的安裝步驟即可使用。它可和PHP、JavaScript、ASP、ASP.NET、ColdFusion、Java、以及ABAP等不同的程式設計語言相結合。FCK的配置和使用都很簡單,但是預設的配置不能滿足所有的需求,所以我們需要瞭解一些FCK的進階功能。

 

擷取FCK的執行個體

FCKeditorAPI是FCKeditor載入後註冊的一個全域對象,利用它我們就可以完成對編輯器的各種操作。

在當前頁獲得 FCK 編輯器執行個體:
var Editor = FCKeditorAPI.GetInstance('InstanceName');

從 FCK 編輯器的快顯視窗中獲得 FCK 編輯器執行個體:
var Editor = window.parent.InnerDialogLoaded().FCK;

從架構頁面的子架構中獲得其它子架構的 FCK 編輯器執行個體:
var Editor = window.FrameName.FCKeditorAPI.GetInstance('InstanceName');

從頁面快顯視窗中獲得父視窗的 FCK 編輯器執行個體:
var Editor = opener.FCKeditorAPI.GetInstance('InstanceName');

 

FCK擷取焦點

擷取焦點是否在FCK中:

oEditor.HasFocus

FCK擷取焦點:

oEditor.Focus();//擷取焦點

 

擷取和設定FCK的內容

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

 

設定 FCK 編輯器的內容:
oEditor.SetHTML("content", false); // 第二個參數為:true|false,是否以所見即所得 (WYSIWYG)方式設定其內容。

 

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

 

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

 

 1 // 擷取編輯器中HTML內容
 2 function getEditorHTMLContents(EditorName) { 
 3     var oEditor = FCKeditorAPI.GetInstance(EditorName); 
 4     return(oEditor.GetXHTML(true)); 
 5 }
 6 
 7 // 擷取編輯器中文字內容
 8 function getEditorTextContents(EditorName) { 
 9     var oEditor = FCKeditorAPI.GetInstance(EditorName); 
10     return(oEditor.EditorDocument.body.innerText); 
11 }
12 
13 // 設定編輯器中內容
14 function SetEditorContents(EditorName, ContentStr) { 
15     var oEditor = FCKeditorAPI.GetInstance(EditorName) ; 
16     oEditor.SetHTML(ContentStr) ; 
17 }
18 

 

 

FCK的事件處理

FCK定義有OnComplete,OnBlur和OnFocus等事件,這樣就可以使用事件的處理函數完成相應的處理。

FCK添加事件處理函數的方法是:fckInstance.Events.AttachEvent( EventName, function)

代碼

//FCKeditor載入完成後做處理的方法
function FCKeditor_OnComplete( editorInstance ) 

    editorInstance.Events.AttachEvent( 'OnBlur' , FCKeditor_OnBlur ) ; 
    editorInstance.Events.AttachEvent( 'OnFocus', FCKeditor_OnFocus ) ; 
}

function FCKeditor_OnBlur( editorInstance ) 
{
    //失去焦點收合工具列
    editorInstance.ToolbarSet.Collapse() ; 
}

function FCKeditor_OnFocus( editorInstance ) 

    editorInstance.ToolbarSet.Expand() ; 
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.