Simple implementation of WYSIWYG richeditor

Source: Internet
Author: User

The overall idea is as follows:
1. Create an IFRAME;
2. Set designMode to "on" to allow editing;
3. When you click the button (you can change it to an image), Execcommand is used to add tags.
About designMode:
Indicates whether the webpage content can be edited. In IE, it corresponds to document. Body. contenteditable.
The following is a WYSIWYG editor that contains "bold", "italic", and "underline" functions. Of course, it is not actually "rich ", however, we can use a similar approach to add other features. Jquery is used in a few places. In fact, it is not difficult to implement it by yourself.

<Input type = "button" value = "B" onclick = "editor.doc.exe ccommand ('bold ')">
<Input type = "button" value = "I" onclick = "editor.doc.exe ccommand ('italic ')">
<Input type = "button" value = "U" onclick = "editor.doc.exe ccommand ('underline')">

<Br/> Debt Recovery
<IFRAME id = "frame" frameborder = "0" style = "border: 1px solid"> </iframe>
<Br/>
<Input type = "button" value = "get value" onclick = "alert((editor.doc.body).html ()">
 
<SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "editor. js"> </SCRIPT>

Editor. js content:

Editor = {
Init: function (){
VaR Ie = $. browser. MSIE;
Editor.doc = ('{frame'{0}.content}{doc ument;

If (IE ){
Editor.doc. Body. contenteditable = true;
} Else {
Editor.doc. designMode = "on ";
}
} Wind fashion Java-JavaScript mogujie.com women's clothing
};

$ (Function (){
Editor. INIT ();
});

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.