CKEditor删除和标签

时间:2016-03-16 06:36:51

标签: javascript html ckeditor

我使用CKEditor,如果我点击Source按钮并粘贴HTML代码,如下所示:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html" />
</head>
<body>
<p>test</p>
</body>
</html>

然后再次点击“来源”,然后提交表单,htmlheadbody标记将被删除,只停留<p>test</p>

CKEditor配置:

CKEDITOR.replace('content', {
            extraPlugins: 'font,panelbutton,colorbutton,colordialog,justify,indentblock,aparat,buyLink',
            autoGrow_onStartup: true,
            enterMode: CKEDITOR.ENTER_BR,
            FullPage : false,
            allowedContent : true,
            ProtectedTags : 'html|head|body'
        });

你能帮助我吗?

2 个答案:

答案 0 :(得分:7)

如果您要使用<html><head><body>元素修改整个HTML页面,则需要将config.fullPage选项设置为true

CKEDITOR.replace( 'content', {
    fullPage: true,
    extraPlugins: 'font,panelbutton,colorbutton,colordialog,justify,indentblock,aparat,buyLink',
    // You may want to disable content filtering because if you use full page mode, you probably
    // want to  freely enter any HTML content in source mode without any limitations.
    allowedContent: true,
    autoGrow_onStartup: true,
    enterMode: CKEDITOR.ENTER_BR
} );

请注意在配置中使用正确的案例(fullPage不是FullPage)。有关更多信息,另请参阅以下资源:

如果您想使用config.autoGrow_onStartup选项,则需要在设置中加入Auto Grow插件。

最后但并非最不重要的是,不建议将Enter Mode设置更改为BRDIV。所有编辑器功能和插件都完全支持默认的CKEDITOR.ENTER_P模式,就创建Web内容的最佳做法而言,它也是最正确的模式。

如果你这样做来控制段落间距,你应该使用样式表。编辑contents.css文件并为<p>元素设置合适的边距值,例如:

p { margin: 0; }

答案 1 :(得分:0)

只需添加以下代码即可防止编辑器从您的源代码中删除“ HEAD / BODY / HTML”标签:-

CKEDITOR.replace( 'editor1', {              
    fullPage: true,
    allowedContent: true,
    autoGrow_onStartup: true,
    enterMode: CKEDITOR.ENTER_BR
});
相关问题