HtmlEdit是iframe對(duì)象ID
IE 中可以設(shè)置contentEditable="true"
把div的contentEditable屬性設(shè)置為 true,在IE瀏覽器中就可以看到效果了,div中元素都變成可以編輯的了。
<div id="tt" contentEditable="true"></div>
<body contentEditable="true"><!--則整個(gè)頁(yè)面都可以編輯了-->。
Firefox中可以 使用javascript語(yǔ)句設(shè)置屬性contentDocument.designMode為 "on"
iframeName.document.designMode="on" ;
其中iframeName 為iframe控件的name屬性。
在 IE7和 FireFox2.0中測(cè)試通過(guò)。如果想先初始化加入一些內(nèi)容及樣式,代碼示例如下:
復(fù)制代碼代碼如下:
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;
}