CKEditor删除<title> </title>标记

时间:2017-08-07 15:58:54

标签: html ckeditor ckeditor4.x

经过几天的搜索并试图解决,无处可去。

CKEditor 4.7.0正在剥离<title></title>标记之间的内容。 无论标题标签的使用方式和位置如何,我都需要CKEDitor单独保留标题内容。

我试过了:

  • allowedContent:true,
  • extraAllowedContent:'title',
  • extraAllowedContent:'title [*]',
  • config.allowedContent = true; (在config.js中)
  • CKEDITOR.dtd。$ removeEmpty ['title'] = false; (在config.js中)

上面没有运气。然后在这里尝试了ckeditor deteles page <title></title> title这个有效的建议,但我最终得到了:

<!DOCTYPE html>
<html>
<head>
    <title>OK Title</title>
</head>
<body>&nbsp;</body>
</html>
<p><br />
<title></title>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content="Web template presented with pure css."><meta name="keywords" content="css template"></p>
<link href="style.css" rel="stylesheet" />
<link href="red.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" /><!-- Header -->
<header class="w3-container w3-theme w3-padding" id="myHeader">
<div class="w3-center">
<h4>BEAUTIFUL RESPONSIVE WEB SITES</h4>

我正在做的是将来自https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_templates_black&stacked=h

的示例CSS模板粘贴到CKEditor中

我明白这不是标准HTML应该显示的方式(不是规范),但是我需要阻止CKEditor修改标题标签,无论如何,只要忽略它并让我在任何地方使用它:)这只是一个教室的简单项目,没有人看到页面的来源,当我在学习白板上的页面时,我需要在浏览器选项卡中显示标题标签。

UPDATE:确实发现我是否在视图中保存了源代码,CKEditor不会修改标题标记。以这种方式工作,但在视觉模式下不喜欢有:)

1 个答案:

答案 0 :(得分:2)

看起来无穷无尽的搜索在重复的论坛上发现了一些信息。有这么多的链接打开丢失的确切网站的轨道获取信息,抱歉。

通过在CKEditor 4.7.0中的config.js中添加以下内容解决了这个问题:

config.allowedContent = true;
config.protectedSource.push(/<title>[\s\S]*?<\/title>/gi); // allow content between <title></title>

希望这会帮助别人:)