Skip to content

Instantly share code, notes, and snippets.

@sinri
Created March 22, 2017 16:17
Show Gist options
  • Save sinri/8c527e03c3fc18d7268a58a04150ba93 to your computer and use it in GitHub Desktop.
Save sinri/8c527e03c3fc18d7268a58a04150ba93 to your computer and use it in GitHub Desktop.
sample of Paste Image From Clipboard
<!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