【问题标题】:paste image with clipboard API - CKEditor使用剪贴板 API 粘贴图像 - CKEditor
【发布时间】: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


    【解决方案1】:

    editor.on('paste', function (event)... 中的event 不是原创事件。

    here,可以得到CKEDITOR.eventInfo对象。

    因此,从文档中,event.data.dataValue 可以访问数据,而无需使用剪贴板 API。

    您可以通过Clipboard Integration获取更多信息。

    更新

    试试这个来获取数据。

    CKEDITOR.on('instanceReady', function (event) {
        event.editor.on('paste', function (pasteEvent) {
          var items = pasteEvent.data.dataValue;
          console.log(JSON.stringify(items));
        });
    });
    

    【讨论】:

    • 我没看懂文档,我多修改了一点代码,但对功能没有影响@fumi_hwh
    • 只需使用event.data.dataValue 从粘贴事件中获取数据
    • 现在错误发生了变化,它显示:“不允许加载本地资源:”,正在粘贴带有物理源@fumi_hwh的图像
    • 其实是另一个问题。或许你可以从here找到答案
    • 好的,我很好奇,因为 ckeditor 在物理源之后放置了相同的 base64“版本”,你知道它为什么会发生吗?
    猜你喜欢
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    相关资源
    最近更新 更多