0
点赞
收藏
分享

微信扫一扫

CKEDITOR 展示word中复制的内容和多张图片

从word中复制全部内容(包括文字、多图片),并在富文本框内展示(CKEDITOR)
CKEDITOR.instances["editor"].on('instanceReady', function(elem) {

console.log(elem.editor.element);
        elem.editor.on("paste", function(e) {
            console.log(e);
            var items = e.data.dataTransfer.$.items;
            for(var i = 0; i < items.length; ++i) {
                var item = items[i];
                if(item.kind == 'file' && item.type == 'image/png') {
                    var imgFile = item.getAsFile();
                    console.log(imgFile);
                    if(!imgFile) {
                        return true;
                    }
                    var reader = new FileReader();
                    reader.readAsDataURL(imgFile);
                    reader.onload = function(e) {
                        //显示文件
                        CKEDITOR.instances["editor"].insertHtml('<img src="' + this.result + '" alt="" />');
                    }
                    return false;
                }
            }
        });
    });

Not allowed to load local resource: file:///C:/。。。。。。。。。。。。。。。。。。。。。。。。。。。.tmp.png
Not allowed to load local resource: file:///C:/。。。。。。。。。。。。。。。。。。。。。。。。。。。.tmp.png

获取剪切板中的图片文件并遍历,遍历中转换图片格式为base64之后再插入剪切板的html中去
CKEDITOR 能同时展示一次性复制word中的所有内容(包括文字和多张图片)

参考文章:http://blog.ncmem.com/wordpress/2023/09/15/ckeditor-展示word中复制的内容和多张图片/


举报

相关推荐

0 条评论