一、配置fckconfig.js文件:
......
//缺省语言:
FCKConfig.AutoDetectLanguage = false ;
FCKConfig.DefaultLanguage = 'zh-cn' ;
//字体设置:
FCKConfig.FontNames = '宋体/宋体;黑体/黑体;仿宋/仿宋;楷体/楷体;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;'+'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
//以换行代替分段:
FCKConfig.EnterMode = 'br' ;
//打开上传文件功能:
//浏览上传:
FCKConfig.LinkBrowser = true ;
FCKConfig.ImageBrowser = true ;
FCKConfig.FlashBrowser = true ;
快速上传:
FCKConfig.LinkUpload = true ;
FCKConfig.ImageUpload = true ;
FCKConfig.FlashUpload = true ;
//上传所使用的语言
var _FileBrowserLanguage = 'php' ;
var _QuickUploadLanguage = 'php' ;
......
二、上传配置(php):config.php
//打开上传功能
$Config['Enabled'] = true ;
//设置文件存放路径:
$Config['UserFilesPath'] = '/userfiles/'.date('Y/m/') ;
//修改各类文件上传及浏览路径(file,image,flash...):
//浏览路径
$Config['FileTypesPath']['File'] = $Config['UserFilesPath'] . 'file/' ;
//上传路径
$Config['QuickUploadPath']['File'] = $Config['UserFilesPath'] . 'file/' ;
......
三、修改php目录下的commands.php、util.php文件:
//commands.php:修改 move_uploaded_file( $oFile['tmp_name'], $sFilePath )为
move_uploaded_file( $oFile['tmp_name'], iconv("utf-8","gbk",$sFilePath) ) ;
//util.php:修改 return ( utf8_encode( htmlspecialchars( $value ) ) )为
return iconv("GBK", "UTF-8", htmlspecialchars( $value ));
四、 fckeditor的API操作
1、向编辑器插入文本:
function InsertHTML() { // Get the editor instance that we want to interact with. var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Check the active editing mode. if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
{ // Insert the desired HTML.
oEditor.InsertHtml( '- This is some <a href="/Test1.html">sample<\/a> HTML -' ) ;
}
else
alert( 'You must be on WYSIWYG mode!' ) ;
}
2、取得编辑器内容(XHTML):
function GetContents() {
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Get the editor contents in XHTML.
alert( oEditor.GetXHTML( true ) ) ; // "true" means you want it formatted.
}
3、取得编辑器内容(innerHTML):
function GetInnerHTML() {
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
alert( oEditor.EditorDocument.body.innerHTML ) ;
}
4、设置编辑器内容:
function SetContents() {
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Set the editor contents (replace the actual one).
oEditor.SetData( 'This is the <b>new content<\/b> I want in the editor.' ) ;
}
5、取得编辑器内容长度:
function GetLength() {
// This functions shows that you can interact directly with the editor area
// DOM. In this way you have the freedom to do anything you want with it.
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Get the Editor Area DOM (Document object).
var oDOM = oEditor.EditorDocument ;
var iLength ;
// The are two diffent ways to get the text (without HTML markups).
// It is browser specific.
if ( document.all ) // If Internet Explorer.
{ iLength = oDOM.body.innerText.length ; }
else // If Gecko.
{ var r = oDOM.createRange() ;
r.selectNodeContents( oDOM.body ) ;
iLength = r.toString().length ; }
alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ;
}
6、执行编辑命令:
function ExecuteCommand( commandName ) {
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Execute the command.
oEditor.Commands.GetCommand( commandName ).Execute() ;
}
7、检查编辑器内容是否已变化:
//内容是否变化
function CheckIsDirty() {
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
alert( oEditor.IsDirty() ) ;
}
//重置变化标志
function ResetIsDirty() {
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
oEditor.ResetIsDirty() ;
alert( 'The "IsDirty" status has been reset' ) ;
}