[英]How to add custom font css dynamically in ckeditor
我正在向ckeditor动态添加字体。 名称会添加到字体中,而不是CSS。 获取CSS的功能:
function getcss(){
var data;
$.ajax({
url : "/demoProject/fonts/fontStyle",
async:false,
success : function(response) {
data = response;
// CKEDITOR.config.contentsCss = response;
},
error : function(response) {
displayError("Error while getting fonts.");
},
});
console.log("return :" + data);
return data;
}
添加字体名称和样式的功能:
$.ajax({
url : "/demoProject/fonts/getFonts",
success : function(response) {
CKEDITOR.config.contentsCss = getcss();
$.each(response, function(index, item ) {
var font_Name = item.name;
CKEDITOR.config.font_names = font_Name +'/'+font_Name + ';' + CKEDITOR.config.font_names;
});
});
来自数据库的CSS:
@font-face {
font-family: 'windsong';
src: url('../fonts/Tue_Jul_28_09:31:29_IST_2015windsong-webfont.eot');
src: url('../fonts/Tue_Jul_28_09:31:29_IST_2015windsong-webfont.ttf') format('truetype');
font-weight: normal; font-style: normal;}
@font-face {
font-family: 'Decoration';
src: url('../fonts/Tue_Jul_28_13:23:32_IST_2015windsong-webfont.eot');
src: url('../fonts/Tue_Jul_28_13:23:32_IST_2015windsong-webfont.ttf') format('truetype');
font-weight: normal; font-style: normal;
}
我尝试了可能的事情,但没有得到任何有意义的结果。 先感谢您。
我没有找到合适的解决方案。 因此,我做了一个替代方案,而不是将字体静态添加到CSS中,而是动态创建了一个文件,并在该文件中写入了字体。 创建css之后,在CKEDITOR.config.contentsCss ='pathof/dynamic/genrated/file.css';
给出了该文件的路径CKEDITOR.config.contentsCss ='pathof/dynamic/genrated/file.css';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.