【发布时间】:2017-06-06 02:37:38
【问题描述】:
我看到了这个link question,我正在尝试实现这个链接的目的,但是当我粘贴文本或图像时,我在下面收到了这个错误
我正在使用CKeditor,并且正在CKeditor的config.js中配置粘贴事件,代码是:
/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.height = '420px';
};
CKEDITOR.on('instanceReady', function (event) {
event.editor.on('paste', function (event) {
// use event.originalEvent.clipboard for newer chrome versions
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
console.log(JSON.stringify(items)); // will give you the mime types
// find pasted image among pasted items
var blob = null;
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") === 0) {
blob = items[i].getAsFile();
}
}
// load image if there is a pasted image
if (blob !== null) {
var reader = new FileReader();
reader.onload = function(event) {
console.log(event.target.result); // data url!
};
reader.readAsDataURL(blob);
}
});
});
我需要包含剪贴板 API 的任何文件吗?
【问题讨论】:
标签: javascript file-upload ckeditor copy-paste clipboard.js