KindEditor配置步骤

KindEditor配置步骤KindEditor是一套开源的HTML可视化编辑器,主要用于让用户在网站上获得所见即所得编辑效果,兼容IE、Firefox、Chrome、Safari、Opera等主流浏览器。KindEditor使

大家好,又见面了,我是你们的朋友全栈君。

KindEditor是一套开源的HTML可视化编辑器,主要用于让用户在网站上获得所见即所得编辑效果,兼容IE、Firefox、Chrome、Safari、Opera等主流浏览器。 KindEditor使用JavaScript编写,可以无缝的与Java、.NET、PHP、ASP等程序接合。

KindEditor非常适合在CMS、商城、论坛、博客、Wiki、电子邮件等互联网应用上使用,2006年7月首次发布2.0以来,KindEditor依靠出色的用户体验和领先的技术不断扩大编辑器市场占有率,目前在国内已经成为最受欢迎的编辑器之一。

 

目前最新版本 KindEditor 3.5.2,官网及下载地址

 

KindEditor配置步骤:

 

1、在项目中建立KindEditor文件夹,把下载下来后的文件解压,将其中的skins,plugins,kindeditor.js 拷到该KindEditor文件夹目录下;

 

2、在.aspx文件中放入TextBox控件,并设置控件ID

 

    如:<asp:TextBox ID=”txtContent” TextMode=”MultiLine”  runat=”server”></asp:TextBox>

 

3、在.aspx文件中引入kindeditor.js文件及Js代码,可将TextBox控件设置成KindEditor在线编辑器,代码如下:

view sourceprint?

  <script src=”../kindeditor/kindeditor.js” type=”text/javascript”></script>

  <script type=”text/javascript”>

      KE.show({

          id: txtContent,

          imageUploadJson: ‘/handler/upload_json.ashx’,

          items : [

          ‘source’, ‘|’, ‘fullscreen’, ‘undo’, ‘redo’, ‘print’, ‘cut’, ‘copy’, ‘paste’,

          ‘plainpaste’, ‘wordpaste’, ‘|’, ‘justifyleft’, ‘justifycenter’, ‘justifyright’,

          ‘justifyfull’, ‘insertorderedlist’, ‘insertunorderedlist’, ‘indent’, ‘outdent’,’subscript’,

          ‘superscript’, ‘|’, ‘selectall’, ‘-‘,

          ‘title’, ‘fontname’, ‘fontsize’, ‘|’, ‘textcolor’, ‘bgcolor’, ‘bold’,

          ‘italic’, ‘underline’, ‘strikethrough’, ‘removeformat’, ‘|’, ‘image’,

          ‘flash’, ‘media’, ‘advtable’, ‘hr’, ’emoticons’, ‘link’, ‘unlink’

         ]

    });

  </script>

 

其中,id为TextBox控件的ID,imageUploadJson: ‘/handler/upload_json.ashx’可设置图片上传(文件上传设置同理),item为设置编辑器工具栏上的每一个功能是否显示,可根据需要手动增删对应单词,如不需要“HTML代码”功能则删除“‘source’,”;

 

4、在.aspx页面的第一句话及Page指令中加上validaterequest=”false”,禁止.net自动屏蔽上传Html代码;

 

  如:<%@ Page Language=”C#” ValidateRequest=”false”…

 

5、设置完毕,后台可直接通过TextBox的text属性来获取编辑器内容;

 

另:设置KindEditor的图片上传功能

1、在刚才在.aspx页面中添加的js代码中添加imageUploadJson参数,

 

  如:imageUploadJson: ‘/handler/upload_json.ashx’

2、建立一般处理程序页面upload_json.ashx,该页面用于编写文件上传代码,在下载下来的源码有,在asp.net中,稍作修改,代码如下:

view sourceprint?

  using System;

  using System.Collections.Generic;

  using System.Linq;

  using System.Web;

  using System.Collections;

  using System.IO;

  using System.Globalization;

  using LitJson; // 需先手动添加LitJson.dll的引用,在asp.net/bin中

   

  namespace Yongbin.Shop.Web.handler

  {

      /// <summary>

      /// upload_json 的摘要说明

      /// </summary>

      public class upload_json : IHttpHandler

      {

          //文件保存目录路径

        private String savePath = “/upload/” + DateTime.Now.ToString(“yyyyMMdd”) + “/”;  // 修改上传目录

        //文件保存目录URL(显示在kindeditor编辑器中的地址)

        private String saveUrl = “/upload/” + DateTime.Now.ToString(“yyyyMMdd”) + “/”;

        //定义允许上传的文件扩展名

          private String fileTypes = “gif,jpg,jpeg,png,bmp”;

        //最大文件大小

        private int maxSize = 1000000;

 

        private HttpContext context;

 

          public void ProcessRequest(HttpContext context)

        {

              this.context = context;

 

              HttpPostedFile imgFile = context.Request.Files[“imgFile”];

            if (imgFile == null)

            {

                showError(“请选择文件。“);

            }

 

            String dirPath = context.Server.MapPath(savePath);

            if (!Directory.Exists(dirPath))

            {

                  Directory.CreateDirectory(dirPath);  // 复制过来的代码改了这里,自动创建目录

            }

   

              String fileName = imgFile.FileName;

            String fileExt = Path.GetExtension(fileName).ToLower();

            ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(‘,’));

 

            if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize)

            {

                showError(“上传文件大小超过限制。“);

            }

   

              if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(‘,’), fileExt.Substring(1).ToLower()) == -1)

            {

                  showError(“上传文件扩展名是不允许的扩展名。“);

            }

 

              String newFileName = DateTime.Now.ToString(“yyyyMMddHHmmss_ffff”, DateTimeFormatInfo.InvariantInfo) + fileExt;

              String filePath = dirPath + newFileName;

 

              imgFile.SaveAs(filePath);

 

            String fileUrl = saveUrl + newFileName;

 

              Hashtable hash = new Hashtable();

            hash[“error”] = 0;

            hash[“url”] = fileUrl;

            context.Response.AddHeader(“Content-Type”, “text/html; charset=UTF-8”);

              context.Response.Write(JsonMapper.ToJson(hash));

            context.Response.End();

        }

 

        private void showError(string message)

        {

            Hashtable hash = new Hashtable();

            hash[“error”] = 1;

              hash[“message”] = message;

            context.Response.AddHeader(“Content-Type”, “text/html; charset=UTF-8”);

            context.Response.Write(JsonMapper.ToJson(hash));

              context.Response.End();

        }

 

          public bool IsReusable

        {

              get

              {

                  return false;

              }

          }

      }

  }

 

3、配置成功

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/155471.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • common sense security framework

    common sense security framework

    2021年9月4日
  • EFI Shell 命令参考

    EFI Shell 命令参考对于使用使用DOS的人来说,会使用DOS命令是最基本的,而在当今即将盛行的EFIBIOS来说,就有了新的变化,如何操作EFIShell呢?至此我贴出了EFIShell的命令供大家学习。EF

    2022年7月4日
  • 激活成功教程资料大全「建议收藏」

    激活成功教程资料大全「建议收藏」激活成功教程资料大全顶啊!!! DFCG官方论坛http://www.chinadfcg.com/龙族联盟论坛http://www.chinadforce.com/index.php中国狂热激活成功教程联盟-梦想家园社区http://www.5icrack.com/bbs/index.php风飘雪|加密与解密实战攻略|最酷激活成功教程教学,带你轻松进入激活成功教程的殿堂http://www.hx007.com/f

    2022年10月8日
  • [gdc15]<暗黑破坏神3>中的合作模式设计

    [gdc15]<暗黑破坏神3>中的合作模式设计本文中,kevin老师分享暗黑设计团队从游戏的早期一直到现在夺魂之镰资料片,一路过来的探索,纠结和沉淀。最后能逐渐把设计做的更好(有的地方大幅度的简化,不纠结,有些地方则有所增强),kevin老师建立在对于D3本质的认知上,产生了一系列的哲学和原则。

    2022年6月2日
  • 并查集例题_并查集算法

    并查集例题_并查集算法E – 带删除并查集 UVA – 11987 Almost Union-Find

    2022年4月20日
  • ubuntu16.04重启网络服务命令_ubuntu重启服务器命令

    ubuntu16.04重启网络服务命令_ubuntu重启服务器命令在更改网络配置后,我们需要重启网络服务使更改生效。在centos系统中,我们可以通过以下命令重启网络服务:/etc/init.d/networkrestart#orservicenetworkrestartUbuntu14.04重启网络服务无效:servicenetworkingrestartstop:Jobfailedwhilestoppingstart:Jobi

    2022年10月9日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号