2、使用FCKeditor 的 API FCKeditor編輯器,提供了非常豐富的API,用于給End User實現(xiàn)很多想要定制的功能,比如最基本的數(shù)據(jù)驗證,如何在提交的時候用JS判斷當前編輯器區(qū)域內是否有內容,F(xiàn)CK的API提供了GetLength()方法; 再比如如何通過腳本向FCK里插入內容,使用InsertHTML()等; 還有,在用戶定制功能時,中間步驟可能要執(zhí)行FCK的一些內嵌操作,那就用ExecuteCommand()方法。 詳細的API列表,請查看FCKeditor的Wiki。而常用的API,請查看FCK壓縮包里的_samples/html/sample08.html。此處就不貼代碼了。 3、外聯(lián)編輯條(多個編輯域共用一個編輯條) 這個功能是2.3版本才開始提供的,以前版本的FCKeditor要在同一個頁面里用多個編輯器的話,得一個個創(chuàng)建,現(xiàn)在有了這個外聯(lián)功能,就不用那么麻煩了,只需要把工具條放在一個適當?shù)奈恢茫竺婢涂梢詿o限制的創(chuàng)建編輯域了,如圖:
要實現(xiàn)這種功能呢,需要先在頁面中定義一個工具條的容器:divid="xToolbar">/div>,然后再根據(jù)這個容器的id屬性進行設置。 ASP實現(xiàn)代碼: div id="fckToolBar">/div> % Dim oFCKeditor Set oFCKeditor = New FCKeditor with oFCKeditor .BasePath = fckPath .Config("ToolbarLocation") = "Out:fckToolBar" .ToolbarSet = "Basic" .Width = "100%" .Height = "200" .Value = "" .Create "jcontent" .Height = "150" .Value = "" .Create "jreach" end with %>
JAVASCRIPT實現(xiàn)代碼: div id="xToolbar">/div> FCKeditor 1: 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 should use something like this: // oFCKeditor.BasePath = '/fckeditor/' ; // '/fckeditor/' is the default value. var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ; var oFCKeditor = new FCKeditor( 'FCKeditor_1' ) ; oFCKeditor.BasePath = sBasePath ; oFCKeditor.Height = 100 ; oFCKeditor.Config[ 'ToolbarLocation' ] = 'Out:parent(xToolbar)' ; oFCKeditor.Value = 'This is some strong>sample text/strong>. You are using FCKeditor.' ; oFCKeditor.Create() ; //--> /script> br /> FCKeditor 2: script type="text/javascript"> !-- oFCKeditor = new FCKeditor( 'FCKeditor_2' ) ; oFCKeditor.BasePath = sBasePath ; oFCKeditor.Height = 100 ; oFCKeditor.Config[ 'ToolbarLocation' ] = 'Out:parent(xToolbar)' ; oFCKeditor.Value = 'This is some strong>sample text/strong>. You are using FCKeditor.' ; oFCKeditor.Create() ; //--> /script>
此部分的詳細DEMO請參照: _samples/html/sample11.html _samples/html/sample11_frame.html 4、文件管理功能、文件上傳的權限問題 一直以后FCKeditor的文件管理部分的安全是個值得注意,但很多人沒注意到的地方,雖然FCKeditor在各個Release版本中一直存在的一個功能就是對上傳文件類型進行過濾,但是她沒考慮過另一個問題:到底允許誰能上傳?到底誰能瀏覽服務器文件? 之前剛開始用FCKeditor時,我就出現(xiàn)過這個問題,還好NetRube(FCKeditor中文化以及FCKeditor ASP版上傳程序的作者)及時提醒了我,做法是去修改FCK上傳程序,在里面進行權限判斷,并且再在fckconfig.js里把相應的一些功能去掉。但 隨之FCK版本的不斷升級,每升一次都要去改一次配置程序fckconfig.js,我發(fā)覺厭煩了,就沒什么辦法能更好的控制這種配置么?事實上,是有 的。 在fckconfig.js里面,有關于是否打開上傳和瀏覽服務器的設置,在創(chuàng)建FCKeditor時,通過程序來判斷是否創(chuàng)建有上傳瀏覽功能的編輯器。首先,我先在fckconfig.js里面把所有的上傳和瀏覽設置全設為false,接著我使用的代碼如下: ASP版本: % Dim oFCKeditor Set oFCKeditor = New FCKeditor with oFCKeditor .BasePath = fckPath .Config("ToolbarLocation") = "Out:fckToolBar" if request.cookies(site_sn)("issuper")="yes" then .Config("LinkBrowser") = "true" .Config("ImageBrowser") = "true" .Config("FlashBrowser") = "true" .Config("LinkUpload") = "true" .Config("ImageUpload") = "true" .Config("FlashUpload") = "true" end if .ToolbarSet = "Basic" .Width = "100%" .Height = "200" .Value = "" .Create "jcontent" %>