解決一個頁面有兩個FCKeditor時,無法使用FCKeditorAPI.GetInstance的問題
Posted in 九月 18th, 2008 by 阿育 | Filed under 程式設計 | Comments (3)FCKeditor跟Wordpress使用的TinyMCE一樣,都是OpenSource的WYSIWYG Editor(所見即所得編輯器),一直以來比較習慣用FCKeditor這套編輯器來幫網頁加入可以編輯HTML的功能,但今天突然發現如果一個頁面有兩個FCKeditor且在Firefox運行時,若要使用FCKeditorAPI.GetInstance()來取得編輯器的instance,只有第一個可以正確取得,第二個將會是undefined,第三個以上沒試但應該也難逃厄運了。
運行環境:
- Firefox 3.0.1
- FCKeditor 2.6.3
發生錯誤可能原因:
- fckeditorcode_gecko.js 有Bug
- Firefox有Bug或與FCKeditor有小部份衝突
解決概念:
如果是第一個原因,我實在沒興趣把壓縮過的fckeditorcode_gecko.js解回來檢查(壓縮過都還有253K啊!),更別說Firefox有bug能幫上什麼忙了,不過幸好在FCKeditor JavaScript API有提到,可以建立一個名為FCKeditor_OnComplete的callback function,當FCKeditor載入完畢後將會呼叫這個function並傳入一個參數,這個參數就是目前裝載完畢的FCKeditor Instance,只要把這個參數記錄下來,就可以直接使用Instance,不需要用FCKeditorAPI.GetInstance()來取得,這樣一來便解決問題了。
解決方式:
在FCKeditor載入之前加入以下Javascript
//修正FckEditor錯誤
var __fckEditorInstance_ = new Array();//用來儲存FCKeditor Instance的陣列
function FCKeditor_OnComplete( editorInstance )
{
__fckEditorInstance_[editorInstance.Name] = editorInstance;
}
function getFckInst(idname)
{
return __fckEditorInstance_[idname];
}
之後就可以利用getFckInst()來代替FCKeditorAPI.GetInstance()取得FCKeditor Instance





四月 8, 2009 at 11:53 上午
很有用的資訊哦!
感恩!
四月 17, 2009 at 6:10 下午
good
七月 22, 2009 at 8:00 下午
感谢楼主分享
——————————————————————————————————
My web page:http://www.congzong.com
Welcome!!