TinyMCE - Chrome browser - unable to insert images in Chrome, like in FF

I use the TinyMCE WYSIWYG editor , and although you can copy and paste fragments of the image in FireFox , it’s not possible in Chrome strong>.

I tried updating to TinyMCE ver. 4.0.16 (previously there was version 3.5.8), while there was still no possible way to make it work.

Could anyone do this?

An example of how it looks in FireFox:

enter image description here

Thanks in advance!

+4
source share
3 answers

, Chrome v 47. :

function pasteHandler(e) {
   var cbData;
   if (e.clipboardData) {
      cbData = e.clipboardData;
   } else if (window.clipboardData) {
      cbData = window.clipboardData;
   }

   if (e.msConvertURL) {
      var fileList = cbData.files;
      if (fileList.length > 0) {
          for (var i = 0; i < fileList.length; i++) {
              var blob = fileList[i];
              console.log("Image blob: " + blob);
              readPastedBlob(blob);
         }
     }
 }
 if (cbData && cbData.items) {
     if ((text = cbData.getData("text/plain"))) {
         // Text pasting is already handled
         return;
     }
     for (var i = 0; i < cbData.items.length; i++) {
         if (cbData.items[i].type.indexOf('image') !== -1) {
             var blob = cbData.items[i].getAsFile();
             readPastedBlob(blob);
         }
     }
 }

function readPastedBlob(blob) {
    if (blob) {
        reader = new FileReader();
        reader.onload = function(evt) {
            pasteImage(evt.target.result);
        };
        reader.readAsDataURL(blob);
    }
}

function pasteImage(source) {
    var image = "<img src='" + source + "' data-mce-selected='1'></img>";
    window.tinyMCE.execCommand('mceInsertContent', false, image);
}}

init tinyMCE:

tinymce.init({
    selector: "textarea", // change this value according to your HTML
    paste_data_images: true,
    setup: function(editor) {
        editor.on('paste', pasteHandler)
    };
})
+1

. : "TinyMCE"

Tiny MCE , Chrome :

tinymce.init({ selector:'textarea', plugins: [
        "image paste"
    ],
    paste_data_images: true});
0

.

"" "paste_data_images: true"

!

0

Source: https://habr.com/ru/post/1525646/


All Articles