Fck's advanced functions and solutions to common problems

Source: Internet
Author: User

FCKeditor is a WYSIWYG text editor dedicated to the use of open source code on the web page. It is lightweight and can be used without complicated installation steps. It can be combined with different programming languages such as PHP, JavaScript, ASP, ASP. NET, ColdFusion, Java, and ABAP. The configuration and usage of fck are simple, but the default configuration cannot meet all requirements. Therefore, we need to know some advanced functions of fck.

 

Get fck instance

Fckeditorapi is a global object registered after FCKeditor is loaded. You can use it to complete various operations on the editor.

Get the fck editor instance on the current page:
VaR editor = fckeditorapi. getinstance ('instancename ');

Obtain the fck editor instance from the pop-up window of the fck Editor:
VaR editor = Window. Parent. innerdialogloaded (). fck;

Obtain the fck editor instance of other sub-frameworks from the sub-frameworks on the Framework page:
VaR editor = Window. framename. fckeditorapi. getinstance ('instancename ');

Obtain the fck editor instance of the parent window from the pop-up window:
VaR editor = opener. fckeditorapi. getinstance ('instancename ');

 

Fck get focus

Whether to obtain the focus in fck:

Oeditor. hasfocus

Fck focus:

Oeditor. Focus (); // get focus

 

Get and set fck content

Get the fck editor content:
Oeditor. getxhtml (formatted); // formatted: True | false, indicating whether to retrieve data in HTML format.

 

Set the content of the fck Editor:
Oeditor. sethtml ("content", false); // The second parameter is true | false. Whether to set the content in WYSIWYG mode.

 

Insert the content to the fck Editor:
Oeditor. inserthtml ("html"); // "html" is HTML text

 

Check whether the content of the fck editor has changed:
Oeditor. isdirty ();

 

1 // obtain the HTML content in the editor
2 function geteditorhtmlcontents (editorname ){
3 var oeditor = fckeditorapi. getinstance (editorname );
4 return (oeditor. getxhtml (true ));
5}
6
7 // obtain the text in the editor
8 function geteditortextcontents (editorname ){
9 var oeditor = fckeditorapi. getinstance (editorname );
10 return (oeditor. editordocument. Body. innertext );
11}
12
13 // set the content in the editor
14 function seteditorcontents (editorname, contentstr ){
15 var oeditor = fckeditorapi. getinstance (editorname );
16 oeditor. sethtml (contentstr );
17}
18

 

 

Fck event processing

Fck defines events such as oncomplete, onblur, and onfocus, so that the corresponding processing can be completed using the event processing function.

The method for adding an event handler function for fck is fckinstance. Events. attachevent (eventname, function)

Code

// FCKeditor processing method after loading
Function fckeditor_oncomplete (editorinstance)
{
Editorinstance. Events. attachevent ('onblur', fckeditor_onblur );
Editorinstance. Events. attachevent ('onfocused ', fckeditor_onfocus );
}

Function fckeditor_onblur (editorinstance)
{
// Remove the focus and collapse the toolbar
Editorinstance. toolbarset. Collapse ();
}

Function fckeditor_onfocus (editorinstance)
{

Editorinstance. toolbarset. Expand ();
}

 

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.