In chrome, using the window.Clipboard object, is there a way to capture pasted text?
In the code you linked there is a pasteHandler
function with the following:
// Get the items from the clipboard var items = e.clipboardData.items; if (items) { // Loop through all items, looking for any kind of image for (var i = 0; i < items.length; i++) { if (items[i].type.indexOf("image") !== -1) { // We need to represent the image as a file, var blob = items[i].getAsFile(); // and use a URL or webkitURL (whichever is available to the browser) // to create a temporary URL to the object var URLObj = window.URL || window.webkitURL; var source = URLObj.createObjectURL(blob); // The URL can then be used as the source of an image createImage(source); } } }
Chrome developer frame is telling me that items[i] is a DataTransferItem
(reference)
On the reference page I see a kind
property and a getAsString()
method. The latter seems to require a callback function that receives the text as a parameter. So to handle text values using the above script you might modify the section I linked as follows:
// Get the items from the clipboard var items = e.clipboardData.items; if (items) { // Loop through all items, looking for any kind of image for (var i = 0; i < items.length; i++) { if (items[i].type.indexOf("image") !== -1) { // We need to represent the image as a file, var blob = items[i].getAsFile(); // and use a URL or webkitURL (whichever is available to the browser) // to create a temporary URL to the object var URLObj = window.URL || window.webkitURL; var source = URLObj.createObjectURL(blob); // The URL can then be used as the source of an image createImage(source); } if (items[i].kind === "string"){ items[i].getAsString(function(s) { alert(s); }); } } }