(转载)UBB(JS完整版)
<SCRIPT language=JavaScript1.2 defer>
function html_trans(str) {
str = str.replace(/\r/g,"");
str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");
str = str.replace(/<script[^>]*?>([\w\W]*?)<\/script>/ig,"");
str = str.replace(/<style[^>]*?>([\w\W]*?)<\/stylet>/ig,"");
str = str.replace(/<embed[^>]*?>([\w\W]*?)<\/embed>/ig,"");
str = str.replace(/<a[^>]+href="([^"]+)"[^>]*>(.*?)<\/a>/ig,"[url=$1]$2[/url]");
str = str.replace(/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig,"[color=$1]$2[/color]");
str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/ig,"[img]$1[/img]");
str = str.replace(/<param NAME="Movie" value="([^>"]+\.swf)"[^>]*>/ig,"[flash]$1[/flash]");
str = str.replace(/<([\/]?)b>/ig,"[$1b]");
str = str.replace(/<([\/]?)strong>/ig,"[$1b]");
str = str.replace(/<([\/]?)u>/ig,"[$1u]");
str = str.replace(/<([\/]?)i>/ig,"[$1i]");
str = str.replace(/ /g," ");
str = str.replace(/&/g,"&");
str = str.replace(/"/g,"\"");
str = str.replace(/</g,"<");
str = str.replace(/>/g,">");
str = str.replace(/\[url=([^\]]+)\]\[img\]/g,"[img]");
str = str.replace(/\[\/img\]\[\/url\]/g,"[/img]");
str = str.replace(/<br>/ig,"\n");
str = str.replace(/<[^>]*?>/g,"");
str = str.replace(/\n+/g,"\n");
return str;
}
function trans(){
var str = "";
rtf.focus();
rtf.document.body.innerHTML = "";
rtf.document.execCommand("paste");
str = rtf.document.body.innerHTML;
document.all.text2.value=str;
if(str.length == 0) {
alert("剪切版不存在超文本数据!");
return "";
}
return html_trans(str);
}
</SCRIPT>
<TEXTAREA class=input2 id=text style="WIDTH: 100%; HEIGHT: 200px" rows="1" cols="20"></TEXTAREA><BR>
<IFRAME id=rtf style="WIDTH: 720px; HEIGHT: 100px" marginWidth=0 marginHeight=0
src="about:blank" scrolling=yes name="I1"></IFRAME>
<INPUT class=input1 onclick="document.getElementById('text').value = trans()" type=button value=转换剪切板数据>