FCKeditor常见问题(2012.10.13更新)
fck_docprops.html中出现start tag ([option]) not closed在fck_docprops.html中将如下语句:“
<option value='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'>HTML 4.01 Transitional</option>”,改为:
<option value='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'>HTML 4.01 Transitional</option>
表单提交时中文乱码
request.setCharacterEncoding("gb2312");
上传中文文件名的文件会出现乱码
分别对SimpleUploaderServlet.java和ConnectorServlet.java做如下修改:
找到2个程序文件中的DiskFileUpload upload = new DiskFileUpload();,在该行下面添加upload.setHeaderEncoding("UTF-8");
添加字体
默认情况下,FCKEditor在进行文本编辑时,无法使用中文字体。
(1)打开 fckconfig.js 文件,将FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;修改为:FCKConfig.FontNames = '宋体;黑体;幼圆;楷体_GB2312;仿宋_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
(2)打开editor/css/fck_editorarea.css 文件,将font-family: Arial, Verdana, sans-serif;修改为:font-family: 宋体, 黑体, 幼圆, 楷体, 仿宋, Arial, Verdana, sans-serif;
XML request error 404
将fckconfig.js文件中的
var _FileBrowserLanguage = ‘php’ ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = ‘php’ ; // asp | aspx | cfm | lasso | perl | php | py
改成
var _FileBrowserLanguage = ‘jsp’ ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = ‘jsp’ ; // asp | aspx | cfm | lasso | perl | php | py
图片预览中的英文如何去掉
在fckeditor/editor/dialog/fck_image下面的fck_image_preview.html中把英文去掉就可以了。
还有图片上传成功后弹出的提示框里面是英文,要想改成中文,在fckeditor/editor/dialog/fck_image下面的fck_image.js里面修改就OK了
中文文件在浏览器引用时会以uri格式(%)出现
在fckeditor/editor/filemanager/browser/default下面的fck_image_preview.html中把window.top.opener.SetUrl( encodeURI( fileUrl ).replace( '#', '%23' ) ) ;改为window.top.opener.SetUrl( fileUrl ) ;
Times附近有语法错误
http://www.blogjava.net/wangbbs2007/articles/298057.html
即“TImes……ROMAN”字体格式错误,这个错误是很多网页在线编辑器(如:FCK,FreeTextBox)的BUG
三种解决方法:
一、把要发布的内容粘贴到记事本里面,然后在粘贴到网页在线编辑器里面,这样可以避免格式错误。
二、以FreeTextBox为例,将FreeTextBox1.Text替换为FreeTextBox1.Text.Replace("'", "''")问题就可以得到解决,其他网页编辑器的方法也是一样的。
三、提供一种暂时的Client端的解决办法:发布内容时,会提示是否删除word格式,选“是”,并选择将Css,字体格式全部清除。
一种一劳永逸的办法,将FCKEditor1.value替换为FCKEDitor1.value.Replace("'","'")问题就可以解决,例如content = content.Replace("'", "''");
非空验证
<
script type
=
"
text/javascript
"
src
=
"
fckeditor/fckeditor.js
"
></
script
>
< script type = " text/javascript " >
function checkZSForm(){
var content = FCKeditorAPI.GetInstance( " content " ).GetXHTML( true );
if (rbContent == null || rbContent == "" ){
alert( " 请输入内容 " );
return false ;
}
document.form1.submit(); // 不为空则提交表单
}
</ script >
content即FCK的实例名(instanceName)
< script type = " text/javascript " >
function checkZSForm(){
var content = FCKeditorAPI.GetInstance( " content " ).GetXHTML( true );
if (rbContent == null || rbContent == "" ){
alert( " 请输入内容 " );
return false ;
}
document.form1.submit(); // 不为空则提交表单
}
</ script >
页面中的表单内容:
<FCK:editor id="content" basePath="FCKeditor/" height="500">
</FCK:editor>
内容重置
function
reset_fck(){
// form1.reset();
FCKeditorAPI.GetInstance( " content " ).EditorDocument.body.innerHTML = "" ;
}
另外,fck工具栏第4个按钮,“新建”相当于“清空”。
// form1.reset();
FCKeditorAPI.GetInstance( " content " ).EditorDocument.body.innerHTML = "" ;
}
添加删除上传到服务器上的文件(图片可预览)功能
参考:http://www.cnblogs.com/Ghost-Chow/archive/2009/10/15/1584052.html
修改:fckeditor/editor/filemanager/browser/default/frmresourceslist.html
在body区域增加如下代码:
<div id="showFile" style="float:left; display:none; background-color:#999999"></div>//作用是当鼠标移到所上传的文件时显示其相关信息
<iframe id="iframe_del" name="iframe_del" width="0" height="0" scrolling="no"></iframe>//作用是供我们删除上传文件时做动作响应窗口,即是将删除动作在iframe中运行,目的是实现伪无刷新删除效果
<div id="body_content"></div>//作用是显示上传文件及文件夹列表
(1) 在js代码区域中加入:
//
显示文件显示层
function showDiv(fileUrl)
{
var name = fileUrl;
// 获取文件类型
var suffix = name.substring(name.lastIndexOf( " . " ) + 1 );
var div = document.getElementById( " showFile " );
div.content = "" ;
div.style.position = " absolute " ;
div.content += "<table width='256' border='0' cellpadding='3' cellspacing='1' bgcolor='#737357'><tbody><tr><td height='23' align='left' bgcolor='#c7c78f'><table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tbody><tr><td width='47%'> <a href='javascript:void(0);' onClick='hiddenDiv();'><font color='#000000' style='text-decoration:none;'>关闭</font></a></td><td width='53%' align='right'><a href='javascript:void(0);' onClick='if (!confirm(\"确定要删除此文件夹及其子目录吗?\")){return false;}else{DelFile(\""+fileUrl+"\");}'><font color='#000000' style='text-decoration:none;'>删除</font></a> </td></tr></tbody></table></td></tr>";
if (suffix == 'gif' || suffix == 'jpg' || suffix == 'jpeg' || suffix == 'bmp' || suffix == 'png'){
div.content += " <tr><td align='center' bgcolor='#c7c78f'><img src=' " + fileUrl + " ' onload='if(this.width>250) this.width=250' style='margin:3px;'></td></tr> " ;
} else {
div.content += " <tr><td height='35' align='center' bgcolor='#c7c78f'><strong>该类型不能预览</strong></td></tr> " ;
}
div.content += " </tbody></table> " ;
div.innerHTML = div.content;
div.style.display = "" ;
div.style.top = event.y + document.body.scrollTop + 10 ;
div.style.left = event.x + document.body.scrollLeft + 30 ;
}
// 隐藏文件显示层
function hiddenDiv()
{
var div = document.getElementById( " showFile " );
div.style.display = " none " ;
}
// ====Add by BaoSight kwan==2011-03-18==start====
// 这里添加两个function,用于提交删除操作,在删除成功后刷新页面
function DelFile(fileUrl){
if ( fileUrl == null )
return ;
oConnector.SendCommand( 'DelFile', 'FileName = ' + encodeURI(encodeURI(fileUrl)) , DelFileCallBack ) ;
}
function DelFileCallBack(fckXml ){
if (oConnector.CheckError(fckXml ) == 0 )
window.parent.frames['frmResourcesList'].Refresh() ;
}
// ====Add by BaoSight kwan==2011-03-18== end ====
(2) 修改本页面原有js
function showDiv(fileUrl)
{
var name = fileUrl;
// 获取文件类型
var suffix = name.substring(name.lastIndexOf( " . " ) + 1 );
var div = document.getElementById( " showFile " );
div.content = "" ;
div.style.position = " absolute " ;
div.content += "<table width='256' border='0' cellpadding='3' cellspacing='1' bgcolor='#737357'><tbody><tr><td height='23' align='left' bgcolor='#c7c78f'><table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tbody><tr><td width='47%'> <a href='javascript:void(0);' onClick='hiddenDiv();'><font color='#000000' style='text-decoration:none;'>关闭</font></a></td><td width='53%' align='right'><a href='javascript:void(0);' onClick='if (!confirm(\"确定要删除此文件夹及其子目录吗?\")){return false;}else{DelFile(\""+fileUrl+"\");}'><font color='#000000' style='text-decoration:none;'>删除</font></a> </td></tr></tbody></table></td></tr>";
if (suffix == 'gif' || suffix == 'jpg' || suffix == 'jpeg' || suffix == 'bmp' || suffix == 'png'){
div.content += " <tr><td align='center' bgcolor='#c7c78f'><img src=' " + fileUrl + " ' onload='if(this.width>250) this.width=250' style='margin:3px;'></td></tr> " ;
} else {
div.content += " <tr><td height='35' align='center' bgcolor='#c7c78f'><strong>该类型不能预览</strong></td></tr> " ;
}
div.content += " </tbody></table> " ;
div.innerHTML = div.content;
div.style.display = "" ;
div.style.top = event.y + document.body.scrollTop + 10 ;
div.style.left = event.x + document.body.scrollLeft + 30 ;
}
// 隐藏文件显示层
function hiddenDiv()
{
var div = document.getElementById( " showFile " );
div.style.display = " none " ;
}
// ====Add by BaoSight kwan==2011-03-18==start====
// 这里添加两个function,用于提交删除操作,在删除成功后刷新页面
function DelFile(fileUrl){
if ( fileUrl == null )
return ;
oConnector.SendCommand( 'DelFile', 'FileName = ' + encodeURI(encodeURI(fileUrl)) , DelFileCallBack ) ;
}
function DelFileCallBack(fckXml ){
if (oConnector.CheckError(fckXml ) == 0 )
window.parent.frames['frmResourcesList'].Refresh() ;
}
// ====Add by BaoSight kwan==2011-03-18== end ====
oListManager.Clear
=
function
()
{
// document.body.innerHTML = '' ;原有
hiddenDiv(); // 修改的
document.getElementById( " body_content " ).innerHTML = ''; // 修改的
}
oListManager.GetFolderRowHtml = function ( folderName, folderPath )
{
// Build the link to view the folder.
var sLink = ' < a href = " # " onclick = " OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false; " > ' ;
return ' < tr > ' +
' < td width = " 16 " > ' +
sLink +
' < img alt = "" src = " images/Folder.gif " width = " 16 " height = " 16 " border = " 0 " >< \ / a > ' +
' < \ / td >< td nowrap colspan = " 2 " >& nbsp;' +
sLink +
folderName +
' < \ / a > ' +
' < \ / td >< td align = " center " width = " 10% " >< a href = " # " onclick = " if (!confirm(\'确定要删除此文件夹及其子目录吗?\')){return false;}else{DelFile(\''+ProtectPath( folderPath )+ '\');} " > delete </ a >< \ / td >< \ / tr > ' ;
// ====Add by BaoSight kwan==2011-03-18==start====
// 此function将在页面展示一级文件夹,这里添加执行删除文件夹的链接,就是添加一列<TD>
// 【】标记当中为添加内容(使用时将标记去掉即可)
// ====Add by BaoSight kwan==2011-03-18== end ====
}
oListManager.GetFileRowHtml = function ( fileName, fileUrl, fileSize )
{
// Build the link to view the folder.
// var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;
var sLink = ' < a href = " # " onmouseover = " showDiv(\''+ProtectPath(fileUrl)+'\'); " onclick = " OpenFile(\''+ProtectPath( fileUrl )+'\'); return false; " > '; // 修改后
// Get the file icon.
var sIcon = oIcons.GetIcon( fileName ) ;
return ' < tr > ' +
' < td width = " 16 " > ' +
sLink +
' < img alt = "" src = " images/icons/' + sIcon + '.gif " width = " 16 " height = " 16 " border = " 0 " >< \ / a > ' +
' < \ / td >< td >& nbsp;' +
sLink +
fileName +
' < \ / a > ' +
' < \ / td >< td align = " right " nowrap >& nbsp;' +
fileSize +
' KB' + ' < \ / td >< td align = " center " width = " 10% " >< a href = " # " onclick = " if (!confirm(\'确定要删除此文件吗?\')){return false;}else{DelFile(\''+ProtectPath( fileUrl )+ '\');} " > delete </ a >< \ / td >< \ / tr > ' ;
// ====Add by BaoSight kwan==2011-03-18==start====
// 此function将在页面展示与一级文件夹同级的文件,这里添加执行删除文件的链接,同样是添加一列<TD>
// 【】标记当中为添加内容(使用时将标记去掉即可)
// ====Add by BaoSight kwan==2011-03-18== end ====
}
function Refresh()
{
// LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;//原有
hiddenDiv(); // 所作修改,为了刷新列表时默认隐藏文件显示层
LoadResources( oConnector.ResourceType, oConnector.CurrentFolder );
}
修改函数:GetFoldersAndFilesCallBack 找到:
// document.body.innerHTML = oHtml.ToString() ;//原有
document.getElementById( " body_content " ).innerHTML = oHtml.ToString() ; // 修改后
{
// document.body.innerHTML = '' ;原有
hiddenDiv(); // 修改的
document.getElementById( " body_content " ).innerHTML = ''; // 修改的
}
oListManager.GetFolderRowHtml = function ( folderName, folderPath )
{
// Build the link to view the folder.
var sLink = ' < a href = " # " onclick = " OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false; " > ' ;
return ' < tr > ' +
' < td width = " 16 " > ' +
sLink +
' < img alt = "" src = " images/Folder.gif " width = " 16 " height = " 16 " border = " 0 " >< \ / a > ' +
' < \ / td >< td nowrap colspan = " 2 " >& nbsp;' +
sLink +
folderName +
' < \ / a > ' +
' < \ / td >< td align = " center " width = " 10% " >< a href = " # " onclick = " if (!confirm(\'确定要删除此文件夹及其子目录吗?\')){return false;}else{DelFile(\''+ProtectPath( folderPath )+ '\');} " > delete </ a >< \ / td >< \ / tr > ' ;
// ====Add by BaoSight kwan==2011-03-18==start====
// 此function将在页面展示一级文件夹,这里添加执行删除文件夹的链接,就是添加一列<TD>
// 【】标记当中为添加内容(使用时将标记去掉即可)
// ====Add by BaoSight kwan==2011-03-18== end ====
}
oListManager.GetFileRowHtml = function ( fileName, fileUrl, fileSize )
{
// Build the link to view the folder.
// var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;
var sLink = ' < a href = " # " onmouseover = " showDiv(\''+ProtectPath(fileUrl)+'\'); " onclick = " OpenFile(\''+ProtectPath( fileUrl )+'\'); return false; " > '; // 修改后
// Get the file icon.
var sIcon = oIcons.GetIcon( fileName ) ;
return ' < tr > ' +
' < td width = " 16 " > ' +
sLink +
' < img alt = "" src = " images/icons/' + sIcon + '.gif " width = " 16 " height = " 16 " border = " 0 " >< \ / a > ' +
' < \ / td >< td >& nbsp;' +
sLink +
fileName +
' < \ / a > ' +
' < \ / td >< td align = " right " nowrap >& nbsp;' +
fileSize +
' KB' + ' < \ / td >< td align = " center " width = " 10% " >< a href = " # " onclick = " if (!confirm(\'确定要删除此文件吗?\')){return false;}else{DelFile(\''+ProtectPath( fileUrl )+ '\');} " > delete </ a >< \ / td >< \ / tr > ' ;
// ====Add by BaoSight kwan==2011-03-18==start====
// 此function将在页面展示与一级文件夹同级的文件,这里添加执行删除文件的链接,同样是添加一列<TD>
// 【】标记当中为添加内容(使用时将标记去掉即可)
// ====Add by BaoSight kwan==2011-03-18== end ====
}
function Refresh()
{
// LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;//原有
hiddenDiv(); // 所作修改,为了刷新列表时默认隐藏文件显示层
LoadResources( oConnector.ResourceType, oConnector.CurrentFolder );
}
修改函数:GetFoldersAndFilesCallBack 找到:
// document.body.innerHTML = oHtml.ToString() ;//原有
document.getElementById( " body_content " ).innerHTML = oHtml.ToString() ; // 修改后
FCKeditor添加删除功能.rar
另类技巧
修改Fckeditor图片上传功能:http://itxiaoqiang.iteye.com/blog/644756
导入word到Fckeditor:http://itxiaoqiang.iteye.com/blog/643684
支持中文图片名称方案:http://windywindy.iteye.com/blog/551458