FCkEditor的使用

1.在项目中创建FCkEditor的目录,将FCkEditor拷贝进去。

2.在FCkEditor中找到FCkEditor.js,

FCKConfig.DefaultLanguage = 'zh-cn' ; //原来是en
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py 改成aspx
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py

3.引用FredCK.FCKeditorV2.dll

4.配置认证

编辑FCKeditor\editor\filemanager\connectors\aspx\config.aspx 中修改

private bool CheckAuthentication()
{
// WARNING : DO NOT simply return "true". By doing so, you are allowing
// "anyone" to upload and list the files in your server. You must implement
// some kind of session validation here. Even something very simple as...
//
// return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true );
//
// ... where Session[ "IsAuthorized" ] is set to "true" as soon as the
// user logs in your system.
return true; //原来这里是 false;不过还是建议看看上面的警告
}

5.在web.config中加上

  <add key="FCKeditor:BasePath" value="~/fckeditor/" />
  <add key="FCKeditor:UserFilesPath" value="~/UTS/UserFiles/" />

 

6.现在程序中就可以使用FCKeditor,在使用FCKeditor时如果你需要在前台js中操作FCKeditor的话可以参考下面的代码

 

// 获取编辑器中HTML内容
function getEditorHTMLContents(EditorName) {
      var oEditor = FCKeditorAPI.GetInstance(EditorName); //EditorName就是FCKeditor的id
      return(oEditor.GetXHTML(true));
}

// 获取编辑器中文字内容
function getEditorTextContents(EditorName) {
      var oEditor = FCKeditorAPI.GetInstance(EditorName);
      return(oEditor.EditorDocument.body.innerText);
}

// 设置编辑器中内容
function SetEditorContents(EditorName, ContentStr) {
      var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
      oEditor.SetHTML(ContentStr) ;
}

         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 编辑器的内容:
           oEditor.GetXHTML(formatted); // formatted 为:true|false,表示是否按HTML格式取出
          也可用:
           oEditor.GetXHTML();

           设置 FCK 编辑器的内容:
           oEditor.SetHTML("content", false); // 第二个参数为:true|false,是否以所见即所得方式设置其内容。此 方 法常用于"设置初始值"或"表单重置"哦作。
        插入内容到 FCK 编辑器:
        oEditor.InsertHtml("html"); // "html"为HTML文本

检查 FCK 编辑器内容是否发生变化:
oEditor.IsDirty();


我在使用fck时还遇到一个问题:我的ie升级时遇到问题导致ie的版本号在程序中读取不到,于是我的fck始终不显示, 花了我几个小时才解决掉这个问题,fck在.net中构造时是通过在上层节点添加iframe创建的,然而这样肯定会在创建之前检查浏览器的版本号,具体的解决方法就是在FredCK.FCKeditorV2.net项目中找到FCKeditor.cs中的Render方法,将检查浏览器功能去掉即可。

posted @ 2008-10-30 11:31  wenney-wang  阅读(444)  评论(1)    收藏  举报