FCKEDITOR 的高級功能和常見問題的解決方法
更新時間:2010年01月26日 11:42:48 作者:
FCKeditor是一個專門使用在網(wǎng)頁上屬于開放源代碼的所見即所得文字編輯器。它志于輕量化,不需要太復雜的安裝步驟即可使用。
它可和PHP、JavaScript、ASP、ASP.NET、ColdFusion、Java、以及ABAP等不同的編程語言相結(jié)合。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();//獲取焦點
獲取和設(shè)置FCK的內(nèi)容
獲得 FCK 編輯器的內(nèi)容:
oEditor.GetXHTML(formatted); // formatted 為:true|false,表示是否按HTML格式取出。
設(shè)置 FCK 編輯器的內(nèi)容:
oEditor.SetHTML("content", false); // 第二個參數(shù)為:true|false,是否以所見即所得方式設(shè)置其內(nèi)容。
插入內(nèi)容到 FCK 編輯器:
oEditor.InsertHtml("html"); // "html"為HTML文本
檢查 FCK 編輯器內(nèi)容是否發(fā)生變化:
oEditor.IsDirty();
// 獲取編輯器中HTML內(nèi)容
function getEditorHTMLContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.GetXHTML(true));
}
// 獲取編輯器中文字內(nèi)容
function getEditorTextContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.EditorDocument.body.innerText);
}
// 設(shè)置編輯器中內(nèi)容
function SetEditorContents(EditorName, ContentStr) {
var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
oEditor.SetHTML(ContentStr) ;
}
FCK的事件處理
FCK定義有OnComplete,OnBlur和OnFocus等事件,這樣就可以使用事件的處理函數(shù)完成相應(yīng)的處理。
FCK添加事件處理函數(shù)的方法是: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() ;
}
獲取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();//獲取焦點
獲取和設(shè)置FCK的內(nèi)容
獲得 FCK 編輯器的內(nèi)容:
oEditor.GetXHTML(formatted); // formatted 為:true|false,表示是否按HTML格式取出。
設(shè)置 FCK 編輯器的內(nèi)容:
oEditor.SetHTML("content", false); // 第二個參數(shù)為:true|false,是否以所見即所得方式設(shè)置其內(nèi)容。
插入內(nèi)容到 FCK 編輯器:
oEditor.InsertHtml("html"); // "html"為HTML文本
檢查 FCK 編輯器內(nèi)容是否發(fā)生變化:
oEditor.IsDirty();
復制代碼 代碼如下:
// 獲取編輯器中HTML內(nèi)容
function getEditorHTMLContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.GetXHTML(true));
}
// 獲取編輯器中文字內(nèi)容
function getEditorTextContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.EditorDocument.body.innerText);
}
// 設(shè)置編輯器中內(nèi)容
function SetEditorContents(EditorName, ContentStr) {
var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
oEditor.SetHTML(ContentStr) ;
}
FCK的事件處理
FCK定義有OnComplete,OnBlur和OnFocus等事件,這樣就可以使用事件的處理函數(shù)完成相應(yīng)的處理。
FCK添加事件處理函數(shù)的方法是: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() ;
}
您可能感興趣的文章:
- Fckeditor XML Request error:internal server error (500) 解決方法小結(jié)
- FCKeditor編輯器添加圖片上傳功能及圖片路徑問題解決方法
- ie9后瀏覽器fckeditor無法上傳圖片、彈出浮層內(nèi)容不顯示的解決方法
- fckeditor在ie9中無法彈出對話框的解決方法(彈出層兼容問題)
- FCKeditor 圖片上傳進度條不動的解決方法
- asp.net+FCKeditor上傳圖片顯示叉叉圖片無法顯示的問題的解決方法
- 瀏覽器執(zhí)行history.go(-1) FCKeditor編輯框內(nèi)顯示html源代碼的解決方法
- 偽靜態(tài)下不能使用FCKeditor的解決方法
- Ewebeditor及fckeditork單引號問題的解決方法
- FCKeditor 2.6 編碼錯誤導致修改的內(nèi)容出現(xiàn)亂碼的解決方法
- jsp fckeditor 上傳中文圖片亂碼問題的解決方法
- Asp.net FCKEditor 2.6.3 上傳文件沒有權(quán)限解決方法
- fckeditor部署到weblogic出現(xiàn)xml無法讀取及樣式不能顯示問題的解決方法
相關(guān)文章
Edge瀏覽器開發(fā)者工具代碼修改同步到Vscode中
這篇文章主要為答案及介紹了Edge瀏覽器開發(fā)者工具代碼修改同步到Vscode中,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-04-04關(guān)于jsp版ueditor1.2.5的部分問題解決(上傳圖片失敗)
這篇文章主要介紹大家在使用jsp版ueditor1.2.5的碰到的一些問題解決方法,需要的朋友可以參考下2013-06-06CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入圖片)
CKEditor 是著名的 HTML 編輯器,IBM、Oracle、Adobe 等都在用。CKEditor 創(chuàng)建于 2003 年,其前身為 FCKEditor,在 2009 年的時候把“F”去掉了,更名為 CKEditor。2010-03-03eWebEditor 輯器按鈕失效 IE8下eWebEditor編輯器無法使用的解決方法
最近我把IE瀏覽器更新到了IE8.0,在用eWebEditor在線HTML文本編輯器的時候點擊eWebEditor上的所有編輯按鈕都沒用,只看到瀏覽器狀態(tài)欄左下角顯示網(wǎng)頁上有錯誤,于是上網(wǎng)查了一下。終于找到解決的方法,測試后正常。2009-06-06