繁体   English   中英

CKEditor 删除<html>和<body>标签

[英]CKEditor removing <html> and <body> tags

我使用 CKEditor,如果我单击“源代码”按钮并粘贴如下 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'
        });

你能帮我吗?

如果你想用<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; }

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM