Use javascript and dhtml to create an ubb editor (with example code)

Source: Internet
Author: User
Have you seen the abc code editor of The chinaASP forum? Is it cool? To be honest, when I first saw the control that I thought was made in other languages, I found it not so mysterious. A product bbs was created a few days ago. The customer requested to support ubb and also made an editor. Now I will give you some ideas about ubb.
The first problem is the interface problem. In fact, this is a good solution. It is implemented by using onmouseover, onmouseout, and onmousedown of td. The code below is the specific implementation method.
The second is the implementation of text effects, which can be achieved using the execCommand method of textRange.
The following is a simple example. You can save it as an html file and run it directly. The function of this example is to change the selected text in the edit box to bold or italic. You can add other functions by referring to this example.
By the way, save the two images first.
File: ubb.html
<HTML>
<HEAD>
<TITLE> ubb demonstration </TITLE>
</HEAD>
<BODY>
<Br>
<Table width = 300 cellspacing = 2 cellpadding = 2 border = 0 bgcolor = lightgrey>
<Tr>
<Td id = tdBold onclick = doAction ("Bold") onmousedown = "DoDown (tdBold);" onmouseover = "On_Mouseover (tdBold);" onmouseout = "On_Mouseout (tdBold ); ">

</Td>
<Td id = tdItalic onclick = doAction ("Italic") onmousedown = "DoDown (tdItalic);" onmouseover = "On_Mouseover (tdItalic);" onmouseout = "On_Mouseout (tdItalic ); ">

</Td>
<Td width = 268> & nbsp; </td>
</Tr>
<Tr>
<Td colspan = 3>
<Iframe id = Editor name = Editor border = 0 scroll = no width = 300 height = 200>
</Iframe>
</Td>
</Tr>
</Table>
</BODY>
</HTML>
<Script language = javascript>

// Initialize the iframe
Editor.doc ument. designMode = "On ";
Editor.doc ument. open;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.