SHARE
TWEET

Untitled

a guest Mar 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.onpaste = function (event) {
  2.   // use event.originalEvent.clipboard for newer chrome versions
  3.   var items = (event.clipboardData  || event.originalEvent.clipboardData).items;
  4.   console.log(JSON.stringify(items)); // will give you the mime types
  5.   // find pasted image among pasted items
  6.   var blob = null;
  7.   for (var i = 0; i < items.length; i++) {
  8.     if (items[i].type.indexOf("image") === 0) {
  9.       blob = items[i].getAsFile();
  10.     }
  11.   }
  12.   // load image if there is a pasted image
  13.   if (blob !== null) {
  14.     var reader = new FileReader();
  15.     reader.onload = function(event) {
  16.       console.log(event.target.result); // data url!
  17.       document.getElementById("pastedImage").src = event.target.result;
  18.     };
  19.     reader.readAsDataURL(blob);
  20.   }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top