Skip to content

Instantly share code, notes, and snippets.

@johnistan
Created September 26, 2012 17:06
Show Gist options
  • Save johnistan/3789222 to your computer and use it in GitHub Desktop.
Save johnistan/3789222 to your computer and use it in GitHub Desktop.
Image Copy from Clipboard - Chrome only
$doc.onpaste = function(event){
var items = event.clipboardData.items;
console.log(JSON.stringify(items)); // will give you the mime types
var blob = items[0].getAsFile(); //really should loop through
var reader = new $wnd.FileReader();
reader.onloadend = (function(event){
return function(){
var image = new Image();
image.title = "test";
console.log(this.result);
image.src = /^image/.test(this.type) ? this.result : this.result;
image.id = "testid";
$wnd.$('#imageAnchor').after( image );
}
})(blob);
reader.readAsDataURL(blob);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment