[英]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.