How to obtain data from clipboard in Firefox

后端 未结 3 1413
轻奢々
轻奢々 2021-02-06 08:02

I would like to trigger onpaste event on element to retrieve data in clipboard (I want to check if image exists in clipboard and upload it into the server). It works perfect on

3条回答
  •  佛祖请我去吃肉
    2021-02-06 08:46

    Sure I can. In this example I retrieve image from clipboard after using Ctrl+V:

     
    Paste here!
    $('#foo')[0].onpaste = function(e) { setTimeout(function() { var blob = $('#foo img').attr('src'); $.post('/upload/image', {'data': blob}, function(result) { }, 'json'); }, 200); }

    It works with

    element that has contenteditable attribute, but does not work with