編輯器中designMode和contentEditable的屬性的介紹
更新時(shí)間:2008年11月22日 12:33:49 作者:
先解釋一下在線編輯器的原理:首先需要IE5.0以上版本的支持.因?yàn)镮E5.0以上版本有一個(gè)編輯狀態(tài),designMode是document的屬性,意思是設(shè)置或獲取表明文檔是否可被編輯的值,默認(rèn)值為off或Inherit
HtmlEdit.document.designMode="On";
HtmlEdit是iframe對(duì)象ID
IE 中可以設(shè)置contentEditable="true"
把div的contentEditable屬性設(shè)置為 true,在IE瀏覽器中就可以看到效果了,div中元素都變成可以編輯的了。
<div id="tt" contentEditable="true"></div>
<body contentEditable="true"><!--則整個(gè)頁面都可以編輯了-->。
Firefox中可以 使用javascript語句設(shè)置屬性contentDocument.designMode為 "on"
iframeName.document.designMode="on" ;
其中iframeName 為iframe控件的name屬性。
在 IE7和 FireFox2.0中測(cè)試通過。如果想先初始化加入一些內(nèi)容及樣式,代碼示例如下:
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;
}
HtmlEdit是iframe對(duì)象ID
IE 中可以設(shè)置contentEditable="true"
把div的contentEditable屬性設(shè)置為 true,在IE瀏覽器中就可以看到效果了,div中元素都變成可以編輯的了。
<div id="tt" contentEditable="true"></div>
<body contentEditable="true"><!--則整個(gè)頁面都可以編輯了-->。
Firefox中可以 使用javascript語句設(shè)置屬性contentDocument.designMode為 "on"
iframeName.document.designMode="on" ;
其中iframeName 為iframe控件的name屬性。
在 IE7和 FireFox2.0中測(cè)試通過。如果想先初始化加入一些內(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;
}
相關(guān)文章
Fckeditor編輯器內(nèi)容長度限制統(tǒng)計(jì)實(shí)現(xiàn)方法
Fckeditor是一種大家常用的編輯器,但是他不能像網(wǎng)頁表單那樣利用document.getelementbyid能獲取得到值了,它必須通過 FCKeditorAPI來操作,下面看看Fckeditor內(nèi)容長度測(cè)試2012-03-03
ckeditor syntaxhighlighter代碼高亮插件,完美修復(fù)
昨天匆忙發(fā)了個(gè)更新版,今天去找ckeditor的api文檔看了很久,終于找到解決辦法了2011-08-08
Office文檔在線編輯的一個(gè)實(shí)現(xiàn)方法
因?yàn)轫?xiàng)目的關(guān)系,研究了一下Office的在線編輯功能,寫出來共享一下。2010-06-06
javascript 在線文本編輯器實(shí)現(xiàn)代碼
javascript 在線文本編輯器實(shí)現(xiàn)代碼,非常值得學(xué)習(xí)。2010-03-03

