新建JSP页面,添加其JS文件<script type="text/javascript" src="ckeditor/ckeditor.js"></script>


     2.不要写成<script type="text/javascript" src="ckeditor/ckeditor.js />样式,在现有的3.0.1版本中会出现CKEDITOR未定义的脚本错误提示,致使不能生成编辑器。



<textarea rows="30" cols="50" name="editor01">请输入.</textarea>
<script type="text/javascript">CKEDITOR.replace('editor01');</script>




<script type="text/javascript">
= function()
'editor01' );



当然还有一个方法CKEDITOR.appendTo(elementOrId, config) 它可以在特定的dom对象中创建CKEDITOR


<div id="editorSpace"><:/div>

CKEDITOR.appendTo( 'editorSpace' );





The best way to set your configurations is in-page, when creating editor instances. In this way you avoid touching the original distribution files in the CKEditor installation folder, making the upgrade task easier.



CKEDITOR.replace( 'editor1',
        toolbar : 'Basic',
        uiColor : '#9AB8F3'




You can also place your settings inside the config.js file also. You will note that the file is mostly empty by default. You simply need to add the configurations that you want to change. For example:

你也可以在config.js 中加入配置信息,当你打开该文件时你会发觉它几乎为空(默认)。你要做的是把配置信息加入其中。


CKEDITOR.editorConfig = function( config )
    config.language = 'fr';
    config.uiColor = '#AADC6E';


Suppose you have copied config,js inside a folder named "custom" in the root of your web site. You have also renamed the file to "ckeditor_config.js". At that point, you must only set the customConfig setting when creating the editor instances. For example:  


CKEDITOR.replace( 'editor1',
        customConfig : '/custom/ckeditor_config.js'



Configurations Overload Order 配置的优先级

You're not required to use only one of the above configuration options. You can mix all of them, and the configurations will be overloaded properly. The following is configurations loading order when creating an editor instance:


  1. The editor instance is created. At this point all its default configurations are set.
  2. If the customConfig setting has been set "in-page", that file is loaded, otherwise the default config.js file is loaded. All settings in this file override the current instance settings.
  3. If the settings loaded in point "2" also define a new customConfig value, this new file is loaded and its settings overload the current instance settings. This happens recursively for all files until no customConfig is defined.
  4. Finally the settings defined "in-page" override the current instance settings (except customConfig, which has been used at point "1").


Avoiding Loading External Settings Files

It is also possible to completely avoid loading an external configuration file, reducing the number of files loaded. To do that, it's enough to set the customConfig setting to an empty string. For example:

CKEDITOR.replace( 'editor1',
        customConfig : ''

This setting is definitely recommended if you are not setting configurations in the config.js file nor a custom configuration file.





A toolbar definition is a JavaScript array that contains the elements to be displayed in all "toolbar rows" available in the editor. There are two ways to set the desired toolbar definition in the editor. It can be set directly into the "toolbar" setting, or it can instead be set to a configuration named "toolbar_<name>", where "<name>" is a name that can be used to identify the toolbar in the "toolbar" setting. The following is the default setting we have in the editor.


那么以下代码定义了toolbar_Full和toolbar_Basic的两种工具栏配置,并使用了config.toolbar = 'Full';定义当前的编辑器的工具栏为Full。

其中("-") 为空间栏的水平分割,("/") 为换行。


Note that two toolbar definitions have been defined, one named "Full" and the other "Basic". The "Full" definition has been set to be used in the toolbar setting.


You can create as many toolbar definitions as you want inside the configuration file. Later, based on some criteria, you can decide the toolbar to use for each editor instance. For example, with the following code, two editors are created in the page, each one using a different toolbar:


CKEDITOR.replace( 'editor1',
        toolbar : 'MyToolbar'

CKEDITOR.replace( 'editor2',
        toolbar : 'Basic'

It's also possible to set the toolbar definition in-page, when creating the editor instance directly. In that case, just assign it to the toolbar setting directly, for example:



 The Styles Definition

The styles definition is a JavaScript array which is registered by calling the CKEDITOR.addStylesSet() function. A unique name must be assigned to your style definition, so you can later set each editor instance to load it. It means that you can have a single style definition which is shared by several editor instances present on the page.

The following is a sample style definition registration:

通过CKEDITOR.addStylesSet() 函数,我们可以定义一个样式,结合以下的例子,my_styles为样式的名称,具体的样式为一个JAVASCRIPT数组。通过样式的名称我可以让页面的多个编辑器应用该样式。


The above definition registration can be placed inline in the page using the editor, or can even live in an external file, which is loaded "on demand", when needed only (see below).


After that, you must instruct the editor to use your newly registered style definition by using the stylesCombo_stylesSet setting. This may be set into the config.js file, for example:

你可以通过在config.js 加入以下代码使编辑器应用该样式:

config.stylesCombo_stylesSet = 'my_styles';


Using an External Styles Definition File 使用自定义的样式文件

You can include the above styles definition registration call into an external JavaScript file. This is the preferred way for it because it will be loaded only when opening the Styles selection box, enhancing the page loading performance. Users may feel a small loading gap because of it though.

By default, the editor uses the "plugins/stylescombo/styles/default.js" file, which is a "minified" JavaScript file. You can find the uncompressed version of it at "_source/plugins/stylescombo/styles/default.js". You can see it online at our SVN also: It can be used as a template for your custom file.

Your style definition file can be saved anywhere at your web site (or the web). You must just know the URL to reach it. For example, you can save at it at the root of your web site, so you can reach it with "/styles.js", or even place it in a central web site, so you can locate it with "". At that point, simply change the stylesCombo_stylesSet setting to point the editor to your file:


config.stylesCombo_stylesSet = 'my_styles:/styles.js';


config.stylesCombo_stylesSet = 'my_styles:';

Style Rules

The entries inside a style definition are called "style rules". Each rule defines the display name for a single style as well as the element, attributes and css styles to be used for it. The following is the generic representation for it:


The "name" and "element" values are required, while other values are optional.


Style Types

There are three types of style types, each one related to the element used in the style rule:

  • Block styles: applied to the text blocks (paragraphs) as a whole, not limited to the text selection. The elements values for that are: address, div, h1, h2, h3, h4, h5, h6, p and pre.
  • Object styles: applied to special selectable objects (not textual), whenever such selection is supported by the browser. The elements values for that are: a, embed, hr, img, li, object, ol, table, td, tr and ul.
  • Inline styles: applied to text selections for style rules using elements not defined in the other style types.

Output Formatting

 The HTML Writer


Technically speaking, writing the final output is a task executed by the CKEDITOR.htmlWriter class ("writer"), used by the CKEDITOR.htmlDataProcessor class. Therefore, the current writer instance for a specific editor instance can be retrieved by the <editorInstance>.dataProcessor.writer property.

By setting the writer properties, it's possible to configure several output formatting options. The following example is the best way to summarize the most used of them, with their default values:



Setting Writer Rules

Because the writer is a property of each editor instance, and also because it's dependency on the writer plugin to be loaded, the best way to make changes to it is by listening to the "instanceReady" event, so it's safe to assume that the dataProcessor property will be loaded and ready to changes. The following is an example of it, when creating an editor instance:



Another way for it is by using the CKEDITOR object, so all editor instances will be changed:


CKEDITOR.on( 'instanceReady', function( ev )
        // Out self closing tags the HTML4 way, like 
        ev.editor.dataProcessor.writer.selfClosingEnd = '>';


posted @ 2009-11-16 10:10  Fskjb  阅读(187685)  评论(12编辑  收藏  举报