HtmlArea是纯JS+Html的编辑器,理论上可以套在任何语言平台上,经过实际使用可以和Asp.Net 2.0 + Ajax 很好的结合,现在本博客系统已经拿它当作文章编辑器了,下面就是具体安装步骤。
字串1
首先下载HtmlArea3.0,解压到Web项目的某个目录。 字串7
lang/gb.js 是中文语言文件,官方默认是ANSI编码的,如果你的web.config设置为utf-8(默认),则需要用记事本打开gb.js,另存为utf-8格式。
字串4
<script type="text/javascript"> _editor_url = "../HtmlArea/"; _editor_lang = "gb";</script>
字串6
<script type="text/javascript" src="../HtmlArea/htmlarea.js"></script>
字串6
<asp:TextBox ID="HtmlArea" CssClass="htmlarea" runat="server" Height="200px" TextMode="MultiLine" Width="100%"></asp:TextBox>
字串5
protected void Page_Load(object sender, EventArgs e){ 字串3
if (!Page.IsPostBack) { 字串6
字串7
StringBuilder sb = new StringBuilder();
字串1
sb.Append("var editor = null;"); 字串5
sb.Append("function initEditor() {");
字串3
sb.Append("editor = new HTMLArea('" + ArticleBody1.FindControl("HtmlArea").ClientID + "');"); 字串4
字串9
sb.Append("editor.generate();}");sb.Append("document.body.onload=initEditor;");
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "HtmlAreaScript", sb.ToString(), true);} 字串8
} 字串6
如果是UpdatePanel提交,则还须在提交后执行下面语句,重新初始化编辑器:
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "HtmlAreaScript", "initEditor();", true); 字串3