2

I am using Html5 and Jquery. I have paste image/text from clipboard into html canvas.

Is it possible to detect whether clipboard has text or image?

$(document).on('paste','[contenteditable]',function(e) {
    e.preventDefault();

    //Here is it possible to detect whether clipboard has text or image?

    var text = (e.originalEvent || e).clipboardData.getData('text/plain');
});

Thanks!

user755806
  • 5,707
  • 23
  • 92
  • 144
  • http://stackoverflow.com/questions/2176861/javascript-get-clipboard-data-on-paste-event-cross-browser ? – Matthew Shine Mar 10 '14 at 14:59
  • Clipboard content is accessible as shown in the post i've linked, however, it doesn't work in all browsers and some that do work will ask the user if they want to the site to have access to their clipboard. - http://stackoverflow.com/questions/6413036/get-current-clipboard-content – Mark Walters Mar 10 '14 at 15:00
  • https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer#types.28.29 – CBroe Mar 10 '14 at 15:01

1 Answers1

-3

This is what I have on my page, it works for me:

if (e.clipboardData.files.length > 0) {
// Image
} else {
// Text
};

Also I see that this question was posted 6 years ago but hopefully it can help some other people.