<script language="javascript">
document.write ('<iframe src="textbox12.asp" id="message" width="650" height="350" onload="_iframeOnload()"></iframe>')
frames.message.document.designMode = "On";
</script></td></tr>
</form></table>
<div id="eWebEditor_Temp_HTML" style="VISIBILITY: hidden; OVERFLOW: hidden; POSITION: absolute; WIDTH: 1px; HEIGHT: 1px"></div>
<script language="javascript">
function _iframeOnload(){
targetDoc = document.frames.message.document; //这里message与frame的id一致
targetDoc.f=function(e){proxyEvent(e);};
with(targetDoc.body){
attachEvent("onpaste",function(event){document.f(event)});
}
message.document.designMode='On';
}
function proxyEvent(e){
switch(e.type){
case "paste":
fnPaste(e);
break;
}
}
function fnPaste(e) {
e.returnValue = false;
var shtml= GetClipboardHTML();
message.document.selection.createRange().pasteHTML( shtml) ;
}
// 取剪粘板中的格式数据
function GetClipboardHTML() {
var oDiv = document.getElementById("eWebEditor_Temp_HTML")
oDiv.innerHTML = "" ;
var oTextRange = document.body.createTextRange() ;
oTextRange.moveToElementText(oDiv) ;
oTextRange.execCommand("Paste") ;
var sData = oDiv.innerHTML ;
oDiv.innerHTML = "" ;
return removeFormatWrd(sData);
}
function removeFormatWrd(html){
var
__reg_hstr=/^(?:redo|undo)$/i,
__reg_ctrl=/^(?:img|table|object|embed)$/i,
__reg_hsmd=/<(?:img|table|object|embed)/b/i,
__reg_cstl=/(<[^//>]+?)/sstyle/s?=/s?(?:".*?"|[^/s>]+)(.*?>)/gi,
__reg_ccls=/(<[^//>]+?)/sclass/s?=/s?(?:".*?"|[^/s>]+)(.*?>)/gi,
__reg_caln=/(<[^//>]+?)/salign/s?=/s?(?:".*?"|[^/s>]+)(.*?>)/gi,
__reg_none=/^(?:<p.*?> <//p>)+$/i,
__reg_brln=/^(<[/w]+?>)?/s*<br//?>[/s/n/r]*/i,
__reg_nwrp=/(?:<br//?>[/s/n/r]*){2,}/gi,
__reg_nwrd=/<//?[/w]+:[/w]+.*?>/gi,
__reg_flnh=//f/g,
__reg_flns=//n|/r/g,
__reg_fzag=/<(style|script).*?>.*?<///1>/gi,
__reg_ftag=/<//?(?:meta|link|!--/[.+?/]--|[/w]+:[/w]+).*?>/gi,
__reg_ctag=/<(//?)(?:!(?:--)?/[)?([^!]+?)(?=/s|>).*?>/gi,
__reg_tnln=/^(?:ol|ul|li|blockquote|div|code|h/d)$/i,
__reg_tcmd=/<//?(?:span|div|h2|h3|code|center|form|input|select|textarea|iframe|img|a).*?>/i,
__reg_tclr=/^(?:font|span|center|sohu|form|input|select|textarea|iframe|strong|b|u|i|s|em|sub|sup|link|script|strike)$/i,
__reg_rmda=/<embed.*?>(<//embed>)?/gi,
__reg_rimg=/<img[^>]*?id="__(?:music|media)_replacement_[/d]+?".*?name="(.*?)".*?>/gi;
if(__reg_tcmd.test(html)&&window.confirm('您粘贴的内容中含不便阅读和编辑的格式,是否清除原来的格式?'))
{
html = html.replace(__reg_caln,'$1$2');
html = html.replace(__reg_cstl,'$1$2');
html = html.replace(__reg_ccls,'$1$2');
html = html.replace(__reg_brln,'$1');
html = html.replace(__reg_nwrp,'<br/>');
html = html.replace(__reg_nwrd,'');
html = html.replace(__reg_flnh,'/n');
html = html.replace(__reg_flns,'/f');
html = html.replace(__reg_fzag,'')
.replace(__reg_cstl,'$1$2')
.replace(__reg_caln,'$1$2')
.replace(__reg_ctag,function($1,$2,$3){
if(__reg_tclr.test($3))return'';
if(__reg_tnln.test($3))return'<br/>';
if($3.toLowerCase()=='p'&&$2!='/')
return'<p style="text-indent:2em;">';
return $1;
})
.replace(__reg_nwrp,'<br/>')
.replace(__reg_brln,'$1');
}
return html;
}
</script>