Ckeditor/fckeditor use FCKEditor 2.6.5 Quick Use tutorial (with Insert Picture) _ Page Editor

Source: Internet
Author: User
Its open source protocol is based on the GPL, LGPL and MPL. Official website: http://ckeditor.com/

In general, when we edit content, we first read into textarea, and then assign the contents of textarea to the editor. Because the content directly as a string to the editor's Value property assignment using JavaScript code, to let JS code is not subject to the content of double quotes, line change, and so on interference, only first read into the textarea most convenient.

Using FCKeditor 2.6.5
Copy Code code as follows:

<div><textarea id= "fckcontent" name= "content" >cftea</textarea></div>
<script type= "Text/javascript" src= "Fckeditor/fckeditor.js" ></script>
<script type= "Text/javascript" >
<!--
var ofckeditor = new FCKeditor ("Fckcontent");
Ofckeditor.basepath = "fckeditor/"; FCKeditor folder location.
Ofckeditor.create ();
-->
</script>

Originally should use display:none to hide textarea, but in order to see the effect, here does not hide.

This automatically associates the editor with the Fckcontent, FCKeditor automatically reads the contents of the textarea when the page is opened, and automatically assigns its content (automatically to XHTML) to textarea when it is submitted.

Note that our TextArea ID and name value are not the same, why?

This should be the less perfect place for this version, if we set the TEXTAREA ID and name value to be the same, then the FCKeditor text area's name value is also content, Request.Form on the server side ("Content"). Count will have two, our server-side value is slightly inconvenient, we have to use Request.Form ("content") (0). If we set the ID to fckcontent, then the name of the FCKeditor text area is fckcontent, unlike textarea.

Setting the editor width height

var ofckeditor = new FCKeditor ("Fckcontent", 500, 300);
Or
Copy Code code as follows:

var ofckeditor = new FCKeditor ("Fckcontent");
Ofckeditor.width = 500;
Ofckeditor.height = 300;

Set up a sidebar

var ofckeditor = new FCKeditor ("fckcontent", +, "Basic");
Note the fourth parameter, whose optional values are basic, default, note that capitalization is not to be mistaken, representing the Basic toolbar, the default toolbar (all buttons).

Set initial value, set value, take value

Set initial value

Actually setting the initial value is rarely used, because it is generally associated with the textarea, it is simply listed here, do not delve into. Note that it is useless to assign an initial value if the associated textarea exists.

var ofckeditor = new FCKeditor ("Fckcontent2", +, "Default", "cloud-dwelling community");
Or
Copy Code code as follows:

var ofckeditor = new FCKeditor ("Fckcontent2", +, "Default");
Ofckeditor.basepath = "fckeditor/";
Ofckeditor.value = "Cftea"; Must be before the Create
Ofckeditor.create ();

Setting values

To demonstrate this example, it is best to place it in the event handler for the button, with some delay, otherwise it would be said that Fckeditorapi is undefined.
Copy Code code as follows:

var oeditor = fckeditorapi.getinstance ("fckcontent");
Oeditor.sethtml ("cloud-dwelling community");

Take value

To demonstrate this example, it is best to place it in the event handler for the button, with some delay, otherwise it would be said that Fckeditorapi is undefined.
Copy Code code as follows:

var oeditor = fckeditorapi.getinstance ("fckcontent");
Alert (oeditor.getxhtml ()); There is a similar method is gethtml, but do not recommend using gethtml.

It is dangerous for you to do this:
Copy Code code as follows:

var oeditor = fckeditorapi.getinstance ("fckcontent");
Oeditor.sethtml ("cloud-dwelling community");
Alert (oeditor.getxhtml ()); The value here is not necessarily the value assigned to the previous sentence. Because they were too close, the value had not yet been given, and it was alert.

Insert Picture

To demonstrate this example, it is best to place it in the event handler for the button, with some delay, otherwise it would be said that Fckeditorapi is undefined.

Fckeditorapi.getinstance ("Fckcontent"). Inserthtml ("<img src...>");

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.