最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CKEditor removing <html> and <body> tags - Stack Overflow

programmeradmin5浏览0评论

I using CKEditor, and if I click the Source button and paste HTML code like below :

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

and click to Source again and then submit the form, the html , head and , body tags are removed and just stays <p>test</p>!

CKEditor configuration:

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'
        });

Can you help me?

I using CKEditor, and if I click the Source button and paste HTML code like below :

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

and click to Source again and then submit the form, the html , head and , body tags are removed and just stays <p>test</p>!

CKEditor configuration:

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'
        });

Can you help me?

Share Improve this question edited Mar 16, 2016 at 9:35 Anna Tomanek 2,23918 silver badges23 bronze badges asked Mar 16, 2016 at 6:36 B. AzizanB. Azizan 932 gold badges4 silver badges13 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 19

If you want to edit an entire HTML page, with <html>, <head> and <body> elements, you need to set the config.fullPage option to 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
} );

Pay attention to using proper case (fullPage is not FullPage) in your configuration. See also the following resources for more information:

  • Editing Complete HTML Pages sample
  • Full Page Editing with Document Properties Plugin

If you want to use the config.autoGrow_onStartup option, you need to include the Auto Grow plugin in your setup.

Last but not least, changing the Enter Mode setting to BR or DIV is not recommended. The default CKEDITOR.ENTER_P mode is fully supported by all editor features and plugins and is also the most correct one in terms of best practices for creating web content.

If you do it to control paragraph spacing, you should use stylesheets instead. Edit the contents.css file and set up a suitable margin value for <p> elements, for example:

p { margin: 0; }

Just add this code to prevent editor to remove 'HEAD/BODY/HTML' tags from your source code:-

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

评论列表(0)

  1. 暂无评论