您好,欢迎访问一九零五行业门户网

HTML在线编辑器的基本概念与相关资料第1/2页_javascript技巧

1,什么是html在线编辑器
顾名思义,在线编辑器就是用于在线编辑的工具,编辑的内容是基于html的文档。
2,html在线编辑器有什么用?
因为html在线编辑器可用于在线编辑基于html的文档,所以,它经常被用于留言板留言、论坛发贴、blog编写日志或等需要用户输入普通html的地方。
3,什么是dhtml
dhtml是一些现有网页技术与标准的整合,通过它,网页设计可以用一种新的方式创建网页。
4,dhtml与html关系
dhtml是以html语言为基础,但是相较于以单纯的html来设计网页的方法,html所带来的最大转变,在于它加入了“对象化”的网页特征。动态html对象模型定义了用于描述网页及其内部元素的对象,每个对象都有描述其自身状态的属性和描述其行为的方法,它们也可以处理特定类型的事件,因此,网页设计者可以通过script程序来控制或调用这些对象。
5,dhtml与html在线编辑器的关系
要做在线编辑器就需要用到dhtml,因为html在线编辑器要能在线地编辑,需要“动态”地改变网页对象的属性,而dhtml正好满足了这个需要。
html在线编辑器有哪些
http://www.cnbruce.com/blog/showlog.asp?cat_id=27&log_id=1021 
html在线编辑器的基本原理
转载自:http://www.lfda.gov.cn/bbsxp/showpost.asp?threadid=692 
看了现在网上流行的在线编辑器,也忍不住想了解一下原理。下了目前应用最广泛的ewebedit,这个是我见到的最强的开源在线编辑器...研究了一天,终于知道了核心原理。
先解释一下在线编辑器的原理:首先需要ie5.0以上版本的支持。因为ie5.0以上版本有一个编辑状态,可以在一个iframe里面输入文字。然后通过 document.body.innerhtml可以获取iframe里面的html代码,这个就是关键。那怎么才能让ifrmae处于编辑状态呢,可以用:
function document.onreadystatechange()
{
htmledit.document.designmode=on;
}
函数实现。剩下的问题就是就是取得焦点和选中的值:
htmledit.focus();
var sel = htmledit.document.selection.createrange();
以上2句可以获取选中的值的html代码。
到了这里,基本原理搞清楚了,然后我们可以用 inserthtml(str)方法将html字符替换掉选种的值。以下就给出一个简单的demo来演示只有加粗效果的在线编辑器。我这里用了一个textarea来或得iframe里的html值,实际情况,可以将textarea的display设置成false,然后就可以将iframe的内容提交了。  
<html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <script language="javascript"> function getiframedata(){ document.form1.test.value=htmledit.document.body.innerhtml; } function sentiframedata(){ htmledit.document.body.innerhtml=document.form1.test.value; } function dob(){ htmledit.focus(); var sel = htmledit.document.selection.createrange(); inserthtml("<b>"+sel.text+"</b>"); } function inserthtml(html) { if (htmledit.document.selection.type.tolowercase() != "none"){ htmledit.document.selection.clear() ; } htmledit.document.selection.createrange().pastehtml(html) ; } function document.onreadystatechange() { htmledit.document.designmode="on"; } </script> </head> <body> <form action="test.asp?act=add" method="post" name="form1"> <iframe id=htmledit style="width: 100%; height: 296px" marginwidth=0 marginheight=0> </iframe> <textarea name="test" rows="10" id="test" style="width:100%;"></textarea> <input type="submit" name="submit" value="提交"> <input type="button" value="iframe->textarea" onclick="getiframedata()"> <input type="button" value="textarea->iframe" onclick="sentiframedata()"> <input type="button" value="b" onclick="dob()"> </form> </body> </html>
首先要有一个编辑框,这个编辑框其实就是一个可编辑状态的网页, 我们用iframe来建立编辑框。
<iframe id=“htmledit” style="width: 100%; height: 296px" marginwidth=“0” marginheight=“0”></iframe>
并且在加上javascript代码来指定htmledit有编辑功能:
<script language="javascript">
var editor;
editor = document.getelementbyid("htmledit").contentwindow;
//只需键入以下设定,iframe立刻变成编辑器。
editor.document.designmode = 'on';
editor.document.contenteditable = true;
//但是ie与firefox有点不同,为了兼容firefox,所以必须创建一个新的document。
editor.document.open();
editor.document.writeln('<html><body></body></html>');
editor.document.close();
//字体特效 - 加粗方法一
function addbold()
{
editor.focus();
//所有字体特效只是使用execcomman()就能完成。
editor.document.execcommand("bold", false, null);
}
//字体特效 - 加粗方法二
function addbold()
{
editor.focus();
//获得选取的焦点
var sel = editor.document.selection.createrange();
inserthtml("<b>"+sel.text+"</b>");
}
function inserthtml(html)
{
if (editor.document.selection.type.tolowercase() != "none")
{
editor.document.selection.clear() ;
}
editor.document.selection.createrange().pastehtml(html) ;
}
</script>
web在线编辑器原理
转载自:http://blog.fhuang.com/article.asp?id=239
从ewebeditor到 fckeditor现在有很多很多的在线编辑器了,功能都很强,很多,但是其基本原理却都很简单
我发现的编辑器主要有3大类,我总结下,把各自的优缺点都写下
直接用textarea 标签
优点:速度快,提交方便,可以用ubb标签来弥补不能所见所得
缺点:不直观,功能非常少
用 div或者table的contenteditable 标签,属性来让一个区域可以编辑
优点:可以很直观,可以做各种效果
缺点:此标签在mozilla下不可用,只适合ie浏览器,且对js要求高
用iframe或者frame的中的document的document.designmode ="on" 来实现可编辑
优点:具有上面第二条的全部优点,并且还多浏览器比如ff等支持
缺点:对js要求高
下面是第三点的一个简单例子代码
<iframe marginheight="1" marginwidth="1" width="400" height="100"></iframe> <script language="javascript"> <!-- //get frame object frameobj=frames[0]; bodyhtml="<head>\n<style type=\"text/css\">body {font: 10pt verdana;}</style>\n</head>\n<body bgcolor=\"#ffffff\" monospace>" bodyhtml += "<style>\np{margin:0px;padding:0px;}\n</style>\n</body>"; frameobj.document.open(); frameobj.document.write(bodyhtml); frameobj.document.close(); frameobj.document.designmode="on"; //--> </script>
其它类似信息

推荐信息