Im Code verknüpfen Sie sich eine ist pasteHandler
Funktion mit dem folgenden:
// 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 Entwicklerrahmen sagt mir, dass Artikel [i] eine Seite DataTransferItem
(reference)
Auf der Referenz ich sehe eine kind
Eigenschaft und eine getAsString()
Methode. Letzteres scheint eine Callback-Funktion zu benötigen, die den Text als Parameter erhält. So Textwerte zu handhaben Sie das Skript verwenden Sie können den Abschnitt ändern I verknüpft wie folgt:
// 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);
});
}
}
}
Hier sind die Angaben für die Zwischenablage Elemente, die Sie gerade arbeiten: http://www.w3.org/TR /2011/WD-html5-20110113/dnd.html#the-datatransferitem-interface. – pimvdb