编辑器中designMode和contentEditable的属性的介绍

  HtmlEdit.document.designMode="On";

  HtmlEdit是iframe对象ID

  IE 中可以设置contentEditable="true"

  把div的contentEditable属性设置为 true,在IE浏览器中就可以看到效果了,div中元素都变成可以编辑的了。

  <div id="tt" contentEditable="true"></div>

  <body contentEditable="true"><!--则整个页面都可以编辑了-->。

  Firefox中可以 使用javascript语句设置属性contentDocument.designMode为 "on"

  iframeName.document.designMode="on" ;

  其中iframeName 为iframe控件的name属性。

  在 IE7和 FireFox2.0中测试通过。如果想先初始化加入一些内容及样式,代码示例如下:

  

复制代码 代码如下:

  if(navigator.appName == "Microsoft Internet Explorer")

  {

  var IframeID=frames["HtmlEditor"];

  if(navigator.appVersion.indexOf("MSIE 6.0",0)==-1){IframeID.document.designMode="On"}

  IframeID.document.open();

  IframeID.document.write(StyleEditorHeader);

  IframeID.document.close();

  IframeID.document.body.contentEditable = "True";

  IframeID.document.body.innerHTML=HidenObjValue;

  IframeID.document.body.style.fontSize="10pt";

  }else

  {

  var _FF = navigator.userAgent.indexOf("Firefox")>-1?true:false;

  var IframeID=getObject("HtmlEditor");

  HtmlEditor=IframeID.contentWindow;

  HtmlEditor.document.designMode="On"

  HtmlEditor.document.open();

  HtmlEditor.document.write(StyleEditorHeader);

  HtmlEditor.document.close();

  HtmlEditor.document.body.contentEditable = "True";

  HtmlEditor.document.body.innerHTML=HidenObjValue;

  }