This function makes it easier to paste UBB.
1. automatically recognize the HTML code of images, hyperlinks, font colors, and fonts that are bold, skewed, and underlined, and convert them to UBB code.
2. compatible with multiple IE and Mozilla browsers
<Html>
<Head>
<Title> Html Conversion Program </title>
<SCRIPT language = "JavaScript1.2">
Function HtmlToUBB (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 (/<a [^>] + href = "([^"] +) "[^>] *> (.*?) <\/A>/ig, "\ n [url = $1] $2 [/url] \ n ");
Str = str. replace (/<font [^>] + color = ([^>] +) [^>] *> (.*?) <\/Font>/ig, "\ n [color = $1] $2 [/color] \ n ");
Str = str. replace (/] + src = "([^"] +) "[^>] *>/ig, "\ n [img] $1 [/img] \ n ");
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 (/<br>/ig, "\ n ");
Str = str. replace (/<[^>] *?> /G ,"");
Str = str. replace (/\ [url = ([^ \] +) \] \ n (\ [img \] \ 1 \ [\/img \]) \ n \ [\/url \]/g, "$2 ");
Str = str. replace (/\ n +/g, "\ n ");
Return str;
}
Function trans (){
Var str = "";
Str = document.getelementbyid('edit'{.content}doc ument. body. innerHTML;
If (str. length = 0 ){
Alert ("no conversion content! Use Ctrl + V to copy the content to the following edit box ");
}
Document. getElementById ('recode'). value = HtmlToUBB (str );
}
Function clearCode (){
Document. getElementById ('recode'). value = "";
}
Function Start (){
Document.getelementbyid('edit'{.content}doc ument. designMode = "on ";
Try {
Document.getelementbyid('edit'{.content}{document.exe cCommand ("undo", false, null );
} Catch (e ){
Alert ("Your Mozilla browser does not support online RichEditor ");
}
}
Function ViewSource (Source ){
Var Html;
If (Source ){
Document. getElementById ('scode'). value = document.getelementbyid('edit'{.content}doc ument. body. innerHTML;
Document. getElementById ('edit'). style. display = "none ";
Document. getElementById ('scode'). style. display = "";
Document. getElementById ('tip '). innerText = "modified and pasted webpage source code> ";
Document. getElementById ('tranclick'). disabled = "disabled"
}
Else {
Document.getelementbyid('edit'{.content}doc ument. body. innerHTML = document. getElementById ('scode'). value;
Document. getElementById ('edit'). style. display = "";
Document. getElementById ('scode'). style. display = "none ";
Document.getelementbyid('edit'{.content}doc ument. designMode = "on ";
Document. getElementById ('tip '). innerText = "use Ctrl + V to copy the content here> ";
Document. getElementById ('tranclick'). disabled = ""
}
}
</SCRIPT>
<Style>
Body {background: # 688ABD; margin: 2px ;}
Label {color: # fff ;}
Th {font-size: 14px; font-family: verdana,; font-weight: bold; color: fc6; text-align: left}
# SCode {width: 400; height: 150px; border: 1px solid #1F2F47; margin-top: 0px! Important; margin-top:-1px; margin-bottom: 0px! Important; margin-bottom:-1px ;}
# ReCode {width: 400; height: 150px; border: 1px solid #1F2F47; font-size: 12px ;}
# Edit {width: 398; height: 148px; border: 1px solid #1F2F47; background: # fff; font-size: 12px}
. Input {
Border-top: 1px solid # fff;
Border-right: 1px solid #003;
Border-bottom: 1px solid #003;
Border-left: 1px solid # fff;
Background: # F4F7FB;
}
. Tip {
Color: # ffc;
Font-weight: bold;
Font-size: 12px;
Font-family:;
}
</Style>
</Head>
<Body onload = "Start ()" style = "">
<Table border = "0" align = "center">
<Tr>
<Th style = ""> Html conversion UBB Program </th>
</Tr>
<Tr>
<Td style = "font-size: 12px;">
<Label for = "Source"> <input type = "checkbox" id = "Source" onclick = "ViewSource (this. checked)"> View Source Code </label>
<Input id = "tranButton" type = "button" value = "Switch" onclick = "trans ()" class = "input">
<Input type = "button" value = "clear" onclick = "clearCode ()" class = "input"> </td>
</Tr>
<Tr>
<Td class = "tip">
<Span id = "tip"> use Ctrl + V to copy the content here >></span> </td>
</Tr>
<Tr>
<Td>
<Textarea id = "sCode" style = "display: none"> </textarea>
<Iframe id = "edit" src = "about: blank" border = "0" frameborder = "0"> </iframe>
</Td>
</Tr>
<Tr>
<Td class = "tip">
Conversion output code >></td>
</Tr>
<Tr>
<Td>
<Textarea id = "ReCode" readonly = "readonly"> </textarea>
</Td>
</Tr>
</Table>
</Body>
</Html>