Created
March 22, 2017 16:17
-
-
Save sinri/8c527e03c3fc18d7268a58a04150ba93 to your computer and use it in GitHub Desktop.
sample of Paste Image From Clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head>sample of Paste Image From Clipboard</head> | |
<body> | |
<h1>sample of Paste Image From Clipboard</h1> | |
<script> | |
// window.addEventListener('paste', ... or | |
document.onpaste = function(event){ | |
var items = (event.clipboardData || event.originalEvent.clipboardData).items; | |
console.log(JSON.stringify(items)); // will give you the mime types | |
for (index in items) { | |
var item = items[index]; | |
if (item.kind === 'file') { | |
var blob = item.getAsFile(); | |
var reader = new FileReader(); | |
reader.onload = function(event){ | |
console.log(event.target.result)}; // data url! | |
reader.readAsDataURL(blob); | |
} | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment