簡體   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