当前位置:asp编程网>贴吧>Javascript吧>  就一个JS的编辑器代码
xiuzhexiuzhe 楼主
xiuzhe
发表于 2013-05-04 18:51:41 回顶端 

原阿塞的,经过优化了

edit.js

//需要的基础变量
var AsaiEdit;
var edit;
var RangeType;
var selection;
var filterScript = false;
var charset="gb2312";
var bLoad=false;
var pureText=true;
var bTextMode=1;
var colour;
//这里是编辑器css的样式
window.onload=function()
 {
 content=document.getElementById(""+an+"").value;
 IFrame.document.body.innerHTML=content;
 document.getElementById(""+an+"").value="";
 }
document.write("");
//段落样式
function FontHBsty(asty)
 {
 if(asty==1)
  {specialtype("

","

");}
 else if(asty==2)
  {specialtype("

","

");}
 else if(asty==3)
  {specialtype("

","

");}
 else if(asty==4)
  {specialtype("

","

");}
 else if(asty==5)
  {specialtype("
","
");}
 else if(asty==6)
  {specialtype("
","
");}
 else if(asty==7)
  {specialtype("","");}
 else if(asty==8)
  {specialtype("

","

");}
 else if(asty==9)
  {specialtype("
","
");}
 else if(asty==10)
  {specialtype("
","
");}
 else if(asty==11)
  {specialtype("","");}
 else if(asty==12)
  {specialtype("","");}
 else if(asty==13)
  {specialtype("
","
");}
 else if(asty==21)
  {specialtype("","");}
 else if(asty==22)
  {specialtype("","");}
 else if(asty==23)
  {specialtype("","");}
 else if(asty==24)
  {specialtype("
","
");}
 else if(asty==25)
  {specialtype("","");}
 else if(asty==26)
  {specialtype("","");}
 else if(asty==27)
  {specialtype("","");}
 else if(asty==28)
  {specialtype("","");}
 else if(asty==29)
  {specialtype("","");}
 else if(asty==30)
  {specialtype("","");}
 else if(asty==31)
  {specialtype("","");}
 else if(asty==32)
  {specialtype("","");}
 else if(asty==33)
  {specialtype("","");}
 else if(asty==91)
  {specialtype("
","
");}
 else if(asty==92)
  {specialtype("
","
");}
 else if(asty==93)
  {specialtype("");}
}
//字体大小
function FontHsize(asty)
 {
 if(asty>7)
  {specialtype("","");}
 else
  {specialtype("","");}
 }
//字体颜色
function foreColor()
 {
 if (!validateMode()) return;
 if (bIsIE5)
  {
  var arr = showModalDialog(""+Sm+""+Se+"meun/selcolor.htm", "", "dialogWidth:299px; dialogHeight:300px; status:0; help:0");
  if (arr != null) FormatText('forecolor', arr);
  else IFrame.focus();
  }
 else
  {FormatText('forecolor', '');}
 }
//字体背景
function backColor()
 {
 if (!validateMode()) return;
 if (bIsIE5)
  {
  var arr = showModalDialog(""+Sm+""+Se+"meun/selcolor.htm", "", "dialogWidth:299px; dialogHeight:300px; status:0; help:0");
  if (arr != null) FormatText('backcolor', arr);
  else IFrame.focus();
  }
 else
  {FormatText('backcolor', '');}
 }
// 粘贴纯文本
function PasteText()
 {
 if (!validateMode()) return;
 IFrame.focus();
 var sText = HTMLEncode(clipboardData.getData("TEXT"));
 IFrame.document.body.innerHTML+=sText;
 IFrame.focus();
 }
// HTMLEncode文本格式化
function HTMLEncode(text)
 {
 text = text.replace(/&/g, "&") ;
 text = text.replace(/"/g, """) ;
 text = text.replace(/  text = text.replace(/>/g, ">") ;
 text = text.replace(/'/g, "’") ;
 text = text.replace(/\ /g," ");
 text = text.replace(/\n/g,"
");
 text = text.replace(/\t/g,"    ");
 return text;
 }
//FLASH
function forswf()
 {
 var arr = showModalDialog(""+Sm+""+Se+"meun/swf.htm", "", "dialogWidth:345px; dialogHeight:220px; status:0; help:0");
 if (arr != null)
  {
  var ss;
  ss=arr.split("*")
  path=ss[0];
  row=ss[1];
  col=ss[2];
  var string;
  string=""
  IFrame.document.body.innerHTML+=string;
  }
 else IFrame.focus();
 }
//wmv
function forwmv()
 {
 var arr = showModalDialog(""+Sm+""+Se+"meun/wmv.htm", "", "dialogWidth:345px; dialogHeight:234px; status:0; help:0");
 if (arr != null)
  {
  var ss;
  ss=arr.split("*")
  path=ss[0];
  autostart=ss[1];
  width=ss[2];
  height=ss[3];
  ran=rand();
  var string;
  var ubbstring;
  string="";
  string="

";
  IFrame.document.body.innerHTML+=string;
  }
 else IFrame.focus();
 }
//rm
function forrm()
 {
 var arr = showModalDialog(""+Sm+""+Se+"meun/rm.htm", "", "dialogWidth:345px; dialogHeight:234px; status:0; help:0");
 if (arr != null)
  {
  var ss;
  ss = arr.split("*")
  path = ss[0];
  row = ss[1];
  col = ss[2];
  autostart = ss[3];
  ran = rand();
  var string;
  string="
";
  IFrame.document.body.innerHTML+=string;
  }
 else IFrame.focus();
 }
//emot表情
function foremot()
 {
 var arr = showModalDialog(""+Sm+""+Se+"meun/emot.htm", "", "dialogWidth:480px; dialogHeight:480px; status:0; help:0");
 if (arr != null)
  {InsertSymbol(arr);IFrame.focus();}
 else IFrame.focus();
 }
//link
function forlink()
 {
 if (bIsIE5)
  {
  var arr=showModalDialog(""+Sm+""+Se+"meun/link.htm","","dialogWidth:24em;dialogHeight:12em;status:0;help:0");
  IFrame.focus();
  if (arr != null)
   {InsertSymbol(arr);IFrame.focus();}
  else IFrame.focus();
  }
 else
  {UserDialog('CreateLink');}
 }
//关于我们
function about()
 {
 var arr = showModalDialog(""+Sm+""+Se+"meun/about.htm", window, "dialogWidth:555px; dialogHeight:282px; status:0; help:0");
 if (arr)
  {IFrame.document.body.innerHTML+=arr;}
 IFrame.focus();
 }
//查找替换
function replace()
 {
 var arr=showModalDialog(""+Sm+""+Se+"meun/replace.htm","","dialogWidth:300px;dialogHeight:180px;status:0;help:0");
 if (arr != null)
  {
  var ss;
  ss = arr.split("*")
  a = ss[0];
  b = ss[1];
  i = ss[2];
  con = IFrame.document.body.innerHTML;
  if (i == 1)
   {con = rCode(con,a,b,true);}
  else
   {con = rCode(con,a,b);}
  IFrame.document.body.innerHTML = con;
  }
 else IFrame.focus();
 }
//插入图片
function Img()
 {
 var arr = showModalDialog(""+Sm+""+Se+"meun/img.htm", window, "dialogWidth:345px; dialogHeight:345px; status:0; help:0");
 if (arr != null)
  {
  var ss;
  ss=arr.split("*")
  a=ss[0];//地址.
  b=ss[1];//alt.
  c=ss[2];//提示
  d=ss[3];//效果.
  e=ss[4];//位置.
  f=ss[5];//长.
  g=ss[6];//宽.
  h=ss[7];//上下.
  i=ss[8];//左右.
  j=ss[9];//边框.
  k=ss[10];//颜色.
  var strpic;
  strpic=""
  if(e.value!="")strpic=strpic+"

"
  strpic=strpic+"   strpic=strpic+" style='"
  if(h.value!='')strpic=strpic+"padding-top:"+h+"px;padding-bottom:"+h+"px;"
  if(i.value!='')strpic=strpic+"padding-top:"+i+"px;padding-bottom:"+i+"px;"
  if(j.value!='')strpic=strpic+"border:"+j+"px "+k+" solid;"
  if(f.value!='')strpic=strpic+"width:"+f+"px;"
  if(g.value!='')strpic=strpic+"height:"+g+"px;"
  if(d.value!='')strpic=strpic+""+d+";"
  strpic=strpic+"'"
  if(b.value!="")strpic=strpic+" alt='"+b+"' "
  strpic=strpic+">"
  if(c.value!="")strpic=strpic+"
"+c+""
  if(e.value!="")strpic=strpic+"

"
  //IFrame.document.body.innerHTML+=strpic; //插入的图片在尾部,以下的插入图片插入在光标位置
  if (arr != null)
   {InsertSymbol(strpic);IFrame.focus();}
  else IFrame.focus();
  }
 IFrame.focus();
 }
//插入特殊符号
function insertSpecialChar()
 {
 var arr = showModalDialog(""+Sm+""+Se+"meun/specialchar.htm", "","dialogWidth:600px; dialogHeight:444px; status:0; help:0");
 if (arr != null) InsertSymbol(arr);
 IFrame.focus() ;
 }
//插入表格
function fortable()
 {
 if (!validateMode()) return;
 IFrame.focus();
 var arr = showModalDialog(""+Sm+""+Se+"meun/table.htm", window, "dialogWidth:345px; dialogHeight:234px; status:0; help:0;scroll:no;");
 if (arr)
  {IFrame.document.body.innerHTML+=arr;}
 IFrame.focus();
 }
//修改表格、插入列+行等 begin
function InsertRow()
 {
 editor = IFrame;
 objReference = GetRangeReference(editor);
 objReference = CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
 switch(objReference.tagName)
  {
  case 'TABLE' :
   var newTable = objReference.cloneNode(true);
   var newRow = newTable.insertRow();
   for(x = 0; x     {var newCell = newRow.insertCell();}
   objReference.outerHTML = newTable.outerHTML;
   break;
  case 'TBODY' :
   var newTable = objReference.cloneNode(true);
   var newRow = newTable.insertRow();
   for(x = 0; x     {var newCell = newRow.insertCell();}
   objReference.outerHTML=newTable.outerHTML;
   break;
  case 'TR' :
   var rowIndex = objReference.rowIndex;
   var parentTable = objReference.parentElement.parentElement;
   var newTable = parentTable.cloneNode(true);
   var newRow = newTable.insertRow(rowIndex+1);
   for(x = 0; x< newTable.rows[0].cells.length; x++)
    {var newCell = newRow.insertCell();}
   parentTable.outerHTML = newTable.outerHTML;
   break;
  case 'TD' :
   var parentRow = objReference.parentElement;
   var rowIndex = parentRow.rowIndex;
   var cellIndex = objReference.cellIndex;
   var parentTable = objReference.parentElement.parentElement.parentElement;
   var newTable = parentTable.cloneNode(true);
   var newRow = newTable.insertRow(rowIndex+1);
   for(x = 0; x< newTable.rows[0].cells.length; x++)
    {
    var newCell = newRow.insertCell();
    if (x == cellIndex)newCell.id='ura';
    }
   parentTable.outerHTML = newTable.outerHTML;
   var r = editor.document.body.createTextRange();
   var item = editor.document.getElementById('ura');
   item.id = '';
   r.moveToElementText(item);
   r.moveStart('character',r.text.length);
   r.select();
  break;
  default :
  return;
  }
 }
//删除行
function DeleteRow()
 {
 editor=IFrame;
 objReference=GetRangeReference(editor);
 objReference=CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
 switch(objReference.tagName)
  {
  case 'TR' :var rowIndex = objReference.rowIndex;
   var parentTable=objReference.parentElement.parentElement;
   parentTable.deleteRow(rowIndex);
   break;
  case 'TD' :var cellIndex=objReference.cellIndex;
   var parentRow=objReference.parentElement;
   var rowIndex = parentRow.rowIndex;
   var parentTable=objReference.parentElement.parentElement.parentElement;
   parentTable.deleteRow(rowIndex);
   if (rowIndex>=parentTable.rows.length)
   {rowIndex=parentTable.rows.length-1;}
  if (rowIndex>=0)
   {
   var r = editor.document.body.createTextRange();
   r.moveToElementText(parentTable.rows[rowIndex].cells[cellIndex]);
   r.moveStart('character',r.text.length);
   r.select();
   }
  else
   {parentTable.removeNode(true);}
  break;
  default :return;
  }
 }
//插入列
function InsertColumn()
 {
 editor = IFrame;
 objReference= GetRangeReference(editor);
 objReference=CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
 switch(objReference.tagName)
  {
  case 'TABLE' :
   var newTable=objReference.cloneNode(true);
   for(x=0; x     {var newCell = newTable.rows[x].insertCell();}
   newCell.focus();
   objReference.outerHTML=newTable.outerHTML;
   break;
  case 'TBODY' :
   var newTable=objReference.cloneNode(true);
   for(x=0; x     {var newCell = newTable.rows[x].insertCell();}
   objReference.outerHTML=newTable.outerHTML;
   break;
  case 'TR' :
   objReference=objReference.parentElement.parentElement;
   var newTable=objReference.cloneNode(true);
   for(x=0; x     {var newCell = newTable.rows[x].insertCell();}
   objReference.outerHTML=newTable.outerHTML;
   break;
  case 'TD' :
   var cellIndex = objReference.cellIndex;
   var rowIndex=objReference.parentElement.rowIndex;
   var parentTable=objReference.parentElement.parentElement.parentElement;
   var newTable=parentTable.cloneNode(true);
   for(x=0; x     {
    var newCell = newTable.rows[x].insertCell(cellIndex+1);
    if (x==rowIndex)newCell.id='ura';
    }
   parentTable.outerHTML=newTable.outerHTML;
   var r = editor.document.body.createTextRange();
   var item=editor.document.getElementById('ura');
   item.id='';
   r.moveToElementText(item);
   r.moveStart('character',r.text.length);
   r.select();
  break;
  default :
  return;
  }
 }
//删除列
function DeleteColumn()
 {
 editor = IFrame;
 objReference=GetRangeReference(editor);
 objReference=CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
 switch(objReference.tagName)
  {
  case 'TD' :var rowIndex=objReference.parentElement.rowIndex;
  var cellIndex = objReference.cellIndex;
  var parentTable=objReference.parentElement.parentElement.parentElement;
  var newTable=parentTable.cloneNode(true);
  if (newTable.rows[0].cells.length==1)
   {parentTable.removeNode(true);return;}
  for(x=0; x    {
   if (newTable.rows[x].cells[cellIndex]=='[object]')
    {newTable.rows[x].deleteCell(cellIndex);}
   }
  if (cellIndex>=newTable.rows[0].cells.length)
   {cellIndex=newTable.rows[0].cells.length-1;}
  if (cellIndex>=0)  newTable.rows[rowIndex].cells[cellIndex].id='ura';
  parentTable.outerHTML=newTable.outerHTML;
  if (cellIndex>=0)
   {
   var r = editor.document.body.createTextRange();
   var item=editor.document.getElementById('ura');
   item.id='';
   r.moveToElementText(item);
   r.moveStart('character',r.text.length);
   r.select();
   }
  break;
  default :return;
  }
 }
//修改表格、插入列+行等 end

//直接用到的过程 begin

// 插入换行
function InBR()
 {
 if (!validateMode()) return;
 InsertSymbol('
');
 }
// 插入当前时间
function InDATE()
 {
 if (!validateMode()) return;
 InsertSymbol(new Date().toLocaleString()+''.charAt(new Date().getDay()));
 }
//清空
function ClearReset()
 {IFrame.document.body.innerHTML='';IFrame.focus();}
//增加、减小编辑器大小
function Size(num)
 {
 var obj=document.getElementById("Composition");
 if (parseInt(obj.offsetHeight)+num>=100)
  {obj.height = (parseInt(obj.offsetHeight) + num);}
 if (num>0)
  {obj.width="100%";}
 }
//编辑器的设计、预览、源码模式切换
function setMode(n)
 {
 setStyle();
 var cont;
 var arsty=document.getElementById("Ar");
 switch (n)
  {
  case 1:
   arsty.style.display="";
   if (document.getElementById("TabHtml").className=="Aba")
    {
    if (bIsIE5)
     {
     cont=IFrame.document.body.innerText;
     cont=correctUrl(cont);
     if (filterScript)
     cont=FilterScript(cont);
     IFrame.document.body.innerHTML=" "+cont;
     }
    else
     {
     var html = IFrame.document.body.ownerDocument.createRange();
     html.selectNodeContents(IFrame.document.body);
     IFrame.document.body.innerHTML = html.toString();
     }
    }
   break;
  case 2:
   arsty.style.display="none";
   cleanHtml();
   cont=IFrame.document.body.innerHTML;
   cont=rCode(IFrame.document.body.innerHTML," ","");
   cont=correctUrl(cont);
   if (filterScript)
    {cont=FilterScript(cont);}
   if (bIsIE5)
    {IFrame.document.body.innerText=cont;}
   else
    {
    var html=document.createTextNode(cont);
    IFrame.document.body.innerHTML = "";
    IFrame.document.body.appendChild(html);
    }
  break;
  }
 setTab(n);
 bTextMode=n
 }
//选择后的样式变化
function setTab(n)
 {
 var mhtml=document.getElementById("TabHtml");
 var mdesign=document.getElementById("TabDesign");
 if (n==1)
  {mhtml.className="Ab";mdesign.className="Aba";}
 else if (n==2)
  {mhtml.className="Aba";mdesign.className="Ab";}
 }
//基本的格式化文本命令
function FormatText(command, option)
 {
 var codewrite
 if (bIsIE5)
  {
  if (option=="removeFormat")
   {command=option;option=null;}
  IFrame.focus();
  IFrame.document.execCommand(command, false, option);
  pureText = false;
  IFrame.focus();
  }
 else
  {
  if ((command == 'forecolor') || (command == 'backcolor'))
   {
   parent.command = command;
   buttonElement = document.getElementById(command);
   IFrame.focus();
   document.getElementById("colourPalette").style.left = getOffsetLeft(buttonElement) + "px";
   document.getElementById("colourPalette").style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
   if (document.getElementById("colourPalette").style.visibility=="hidden")
    {document.getElementById("colourPalette").style.visibility="visible";}
   else
    {document.getElementById("colourPalette").style.visibility="hidden";}
   var sel = IFrame.document.selection;
   if (sel != null)
    {colour = sel.createRange();}
   }
  else
   {
   IFrame.focus();
   IFrame.document.execCommand(command, false, option);
   pureText = false;
   IFrame.focus();
   }
  }
 }
//清理编辑器内代码
function CleanCode()
 {
 var editor=IFrame;
 editor.focus();
 if (bIsIE5)
  {
  var body = editor.document.body;
  for (var index = 0; index < body.all.length; index++)
   {
   tag = body.all[index];
   tag.removeAttribute("className","",0);
   tag.removeAttribute("style","",0);
   }
  var html = editor.document.body.innerHTML;
  html = html.replace(/


/g,"

");
  html = html.replace(/\[\$br\]/gi,"
");
  editor.document.body.innerHTML = html;
  }
 else
  {
  var html = IFrame.document.body.ownerDocument.createRange();
  html.selectNodeContents(IFrame.document.body);
  IFrame.document.body.innerHTML = html.toString();
  }
 }
//
function correctUrl(cont)
 {
 var regExp;
 var url=location.href.substring(0,location.href.lastIndexOf("/")+1);
 cont=rCode(cont,location.href+"#","#");
 cont=rCode(cont,url,"");
 cont=rCode(cont," ","");
 return cont;
 }
//
function cleanHtml()
 {
 if (bIsIE5)
  {var fonts = IFrame.document.body.all.tags("FONT");}
 else
  {var fonts = IFrame.document.all("FONT");}
 var curr;
 for (var i = fonts.length - 1; i >= 0; i--)
  {curr = fonts[i];if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;}
 }
//
function InsertSymbol(str1)
 {
 IFrame.focus();
 if (bIsIE5) selectRange();
 edit.pasteHTML(str1);
 }
//
function selectRange()
 {
 selection =IFrame.document.selection;
 edit=selection.createRange();
 RangeType =selection.type;
 }
//编辑器里面插入内容用
function specialtype(Mark1, Mark2)
 {
 var strHTML;
 if (bIsIE5)
  {
  selectRange();
  if (RangeType == "Text")
   {
   if (Mark2==null)
    {strHTML = "<" + Mark1 + ">" + edit.htmlText + ""; }
   else
    {strHTML = Mark1 + edit.htmlText +  Mark2; }
   edit.pasteHTML(strHTML);
   IFrame.focus();
   edit.select();
   }
  else
   {window.alert("请选择相应内容!")}
  }
 else
  {
  if (Mark2==null)
   {strHTML="<" + Mark1 + ">" + IFrame.document.body.innerHTML + ""; }
  else
   {strHTML = Mark1 + IFrame.document.body.innerHTML +  Mark2; }
  IFrame.document.body.innerHTML=strHTML
  IFrame.focus();
  }
 }
//
function getText()
 {
 if (bTextMode==2)
 return IFrame.document.body.innerText;
 else
  {cleanHtml();return IFrame.document.body.innerHTML;}
 }
//
function getOffsetTop(elm)
 {
 var mOffsetTop = elm.offsetTop;
 var mOffsetParent = elm.offsetParent;
 while(mOffsetParent)
  {
  mOffsetTop += mOffsetParent.offsetTop;
  mOffsetParent = mOffsetParent.offsetParent;
  }
 return mOffsetTop;
 }
//
function getOffsetLeft(elm)
 {
 var mOffsetLeft = elm.offsetLeft;
 var mOffsetParent = elm.offsetParent;
 while(mOffsetParent)
  {
  mOffsetLeft += mOffsetParent.offsetLeft;
  mOffsetParent = mOffsetParent.offsetParent;
  }
 return mOffsetLeft;
 }
//
function rand()
 {return parseInt((1000)*Math.random()+1);}
//检验连接地址是不是已经输入了
function UserDialog(what)
 {
 if (!validateMode()) return;
 IFrame.focus();
 if (what == "CreateLink")
  {
  if (bIsNC)
   {
   insertLink = prompt("请填写超级链接地址信息:", "http://");
   if ((insertLink != null) && (insertLink != "") && (insertLink != "undefined"))
    {IFrame.document.execCommand('CreateLink', false, insertLink);}
   else
    {IFrame.document.execCommand('unlink', false, null);}
   }
  else
   {IFrame.document.execCommand(what, true, null);}
  }
 if(what == "InsertImage")
  {
  imagePath = prompt('请填写图片链接地址信息:', 'http://');
  if ((imagePath != null) && (imagePath != ""))
   {IFrame.document.execCommand('InsertImage', false, imagePath);}
  IFrame.document.body.innerHTML = (IFrame.document.body.innerHTML).replace("src=\"file://","src=\"");
  }
 pureText = false;
 IFrame.focus();
 }
//
function GetRangeReference(editor)
 {
 editor.focus();
 var objReference = null;
 var RangeType = editor.document.selection.type;
 var selectedRange = editor.document.selection.createRange();
 switch(RangeType)
  {
  case 'Control' :
   if (selectedRange.length > 0 )
    {objReference = selectedRange.item(0);}
   break;
  case 'None' :
   objReference = selectedRange.parentElement();
   break;
  case 'Text' :
   objReference = selectedRange.parentElement();
   break;
  }
 return objReference
 }
//
function CheckTag(item,tagName)
 {
 if (item.tagName.search(tagName)!= -1)
  {return item;}
 if (item.tagName == 'BODY')
  {return false;}
 item=item.parentElement;
 return CheckTag(item,tagName);
 }
//自动排版
function AutoPB()
 {var oBody= IFrame.document.body;}
//超级自动排版
function AsaiPB()
 {PasteText();AutoPB();}
//
function rCode(s,a,b,i)
 {
 a = a.replace("?","\\?");
 if (i==null)
  {var r = new RegExp(a,"gi");}
 else if (i)
  {var r = new RegExp(a,"g");}
 else
  {var r = new RegExp(a,"gi");}
 return s.replace(r,b);
 }
//编辑器内容check和提交代码 beging
//判断提交时候的状态
function validateMode()
 {
 if (bTextMode!=2) return true;
 alert("请取消查看“源码”状态,调至“设计”状态再行提交,谢谢!");
 IFrame.focus();
 return false;
 }
//编辑器内容预览
function View()
 {
 if (bTextMode==2)
  {cont=IFrame.document.body.innerText;}
 else
  {cont=IFrame.document.body.innerHTML;}
 cont=correctUrl(cont);
 bodyTag="";
 if (filterScript)
 cont=FilterScript(cont);
 preWin=window.open('','','');
 preWin.document.open();
 preWin.document.write(bodyTag);
 preWin.document.write(cont);
 preWin.document.close();
 preWin.document.title="提示:您正在预览编辑器中的内容......";
 preWin.document.charset=charset;
 }
//编辑器区域整体样式表现
function InitDocument(hiddenid, charset)
 {
 if (charset!=null)
 charset=charset;
 var bodyTag="";
 if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1)
  {IFrame.document.designMode="On"}
 IFrame.document.open();
 IFrame.document.write ('');
 if (bIsIE5)
  {}
 IFrame.document.write(bodyTag);
 IFrame.document.write("");
 IFrame.document.write("");
 IFrame.document.close();
 IFrame.document.body.contentEditable = "True";
 IFrame.document.charset=charset;
 bLoad=true;
 setStyle();
 }
//编辑器区域滚动条样式
function setStyle()
 {
 var bs = IFrame.document.body.style;
 if (bTextMode==2)
  {
  //bs.fontFamily="Verdana";
  bs.fontSize="12px";
  }
 else
  {
  //bs.fontFamily="Verdana";
  bs.fontSize="12px";
  }
 bs.scrollbarShadowColor= '#'+sy+'';//立体滚动条阴影的颜色
 bs.scrollbar3dLightColor= '#'+by+'';//滚动条亮边的颜色
 bs.scrollbarArrowColor= '#'+sy+'';//上下按钮上三角箭头的颜色
 bs.scrollbarBaseColor= '#'+by+'';//滚动条的基本颜色
 bs.scrollbarDarkShadowColor= '#'+by+'';//滚动条强阴影的颜色
 bs.scrollbarFaceColor= '#'+by+'';//滚动条凸出部分的颜色
 bs.scrollbarHighlightColor= '#'+sy+'';//滚动条空白部分的颜色
 bs.scrollbarTrackColor= '#'+qy+'';//滚动条的背景颜色
 bs.border='0';}
//
function submits()
 {
 var html;
 html=getText();
 html=rCode(html," ","");
 document.getElementById(""+an+"").value=html;
 }
//提交验空
function load_content()
 {
 if(!validateMode())
  {return false;}
 if(chkdiv("title"))
  {
  if(form1.title.value=="")
   {alert("标题不能不写呀!");form1.title.focus();return false;}
  }
 document.getElementById(""+an+"").value=IFrame.document.body.innerHTML;
 if(IFrame.document.body.innerHTML=="")
  {
  if(window.confirm('内容不能为空哦'))
   {return true;}
  else
   {IFrame.document.body.focus();return false;}
  }
 if(chkdiv("CodeStr"))
  {
  if(form1.CodeStr.value=="")
   {alert("验证码还没有填写,请先填写!");form1.CodeStr.focus();return false;}
  }
 return true;
 }
//检测是否有指定的对象
function chkdiv(divid)
 {
 var chkid=document.getElementById(divid);
 if(chkid != null)
  {return true;}
 else
  {return false; }
 }
//去掉所有HTML符号检验是否为空值
function ChekEmptyCode(html)
 {
 html = html.replace(/\<[^>]*>/g,"");
 html = html.replace(/ /gi, "");
 html = html.replace(/o:/gi, "");
 html = html.replace(/\s/gi, "");
 return html;
 }
//
function getHTML()
 {
 var html;
 if (!bTextMode)
  {html = IFrame.document.body.innerHTML}
 else
  {html = IFrame.document.body.innerText}
 return html;
 }
//编辑器内容check和提交代码 end
var ONMT='class="as2" onMouseOver="this.className=\'as1\';" onMouseOut="this.className=\'as2\';"'
var ONDR=Sm+Se+'SysImg/'
if(Sk!==5)
 {
 document.write('

');//菜单宽度
 if((Sk==0)||(Sk==1)||(Sk==2))
  {
  document.write('
')
  document.write('')
  document.write('')
  document.write('
');
  }
 document.write('加粗')
 document.write('斜体')
 document.write('下划线')
 document.write('上标')
 document.write('下标')
 document.write('删除线')
 document.write('插入水平线')
 document.write('插入换行符')
 document.write('字体颜色')
 document.write('字体背景颜色')
 document.write('左对齐')
 document.write('居中')
 document.write('右对齐')
 document.write('编号')
 document.write('项目符号')
 document.write('减少缩进量')
 document.write('增加缩进量')
 document.write('替换')
 document.write('撤消')
 document.write('恢复')
 document.write('全选')
 document.write('剪切')
 document.write('复制')
 document.write('常规粘贴')
 document.write('纯文本粘贴')
 document.write('取消选中文字样式')
 document.write('清理全局HTML代码')
 document.write('自动排版\n在每个段落前添加空格')
 document.write('超级排版\n复制外网内容,单击图标,全自动文本模式排版\n格式全局内容为文本,行头空两格自动排版')
 document.write('插入超级链接')
 document.write('去掉超级链接');
 if(Sk!==3)
  {
  if(Sk!==4)
   {
   document.write('插入当前时间')
   document.write('插入特殊符号')
   document.write('插入表格')
   document.write('插入行')
   document.write('删除行')
   document.write('插入列')
   document.write('删除列')
   document.write('插入表情');
   if(Sk!==2)
    {
    document.write('插入图片')
    document.write('插入Flash及视频网站上的视频')
    document.write('插入Windows Media')
    document.write('插入Real Media');
    }
   }
  }
 document.write('编辑器帮助
');
 }
document.write('
');//编辑器框
if(Sk!==4)
 {if(Sk!==5)
  {
  document.write('
')
  document.write('
设 计<\/div>')
  document.write('
预 览<\/div>')
  document.write('
源 码<\/div>')
  document.write('
清 空<\/div>')
  document.write('
╋<\/div>')
  document.write('
━<\/div>')
  document.write('<\/div>');
  }
 }
var bIsIE5=document.all;
var canusehtml='1';
var PostType=1;
if (bIsIE5)
 {var IFrame=frames["Composition"];}
else
 {
 var IFrame=document.getElementById("Composition").contentWindow;
 var bIsNC=true;
 }
if (bLoad==false)
 {InitDocument("Body",charset);}

 

xiuzhexiuzhe 2楼
xiuzhe
发表于 2013-05-04 19:17:50 回顶端 

实例调用

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">


测试


演示


<%if request("action")="save" then%>
标题:<%=request("title")%>

内容:<%=request("Content")%>
<%end if%>

标题:



内容:









 

wangsdongwangsdong 3楼
wangsdong
发表于 2013-05-06 13:14:41 回顶端 

谢谢楼主分享

共1页 每页20条 页次:1/1
  • 首页
  • 上一页
  • 1
  • 下一页
  • 尾页

关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网