[英]How to add font in font.css for using fonts in CKEDITOR
我想在ckeditor中動態添加字體。 為此,我正在使用config.contentsCss =“”。 它是靜態執行的。 我不知道如何在外部文件中添加CSS,或者有另一種向ckeditor添加@ font-face的方法。 我的代碼是這樣的:
var fontStyle = '';
$.ajax({
url : "/chrysofin/fonts/getFonts",
success : function(response) {
$.each(response, function(index, item ) {
var fontName = item.name;
var eotFile = item.eotPath;
var ttfFile = item.ttfPath;
fontStyle += "@font-face {\n" +
"\tfont-family: \ "+ fontName+"\;\n" +
"\tsrc: url('../invitations/fonts/"+ eotFile +"');\n" +
"\tsrc: url('../invitations/fonts/"+ ttfFile +"') format('truetype');\n" +
"}\n" ;
});
alert(fontStyle);
/*CKEDITOR.config.customConfig = function(config) {
config.contentsCss = fontStyle;
};*/
// CKEDITOR.addCss(fontStyle);
$.each(response, function(index, item ) {
var fontName = item.name;
CKEDITOR.config.font_names = fontName +'/'+fontName + ';' + CKEDITOR.config.font_names;
});
},
error : function() {
displayError("Error while getting fonts.");
},
});
// CKEDITOR.config.contentsCss ='../assets/invitations/fonts/fonts.css';
CKEDITOR.config.font_names = 'Windsong/windsong;' + CKEDITOR.config.font_names;
我也遇到了同樣的問題。 您可以在服務器端創建一個css文件,然后在該文件中寫入css。 在此之后,將此文件路徑傳遞到CKEDITOR.config.contentsCss = "Path/of/file"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.