कोड में आप जुड़े हुए निम्नलिखित के साथ एक pasteHandler
समारोह है:
// 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 डेवलपर फ्रेम कह रहा है कि आइटम [i] एक DataTransferItem
(reference)
संदर्भ पृष्ठ मैं देख रहा हूँ पर है kind
संपत्ति और getAsString()
विधि। उत्तरार्द्ध को एक कॉलबैक फ़ंक्शन की आवश्यकता होती है जो पाठ को पैरामीटर के रूप में प्राप्त करता है। इसलिए उपरोक्त स्क्रिप्ट का उपयोग कर पाठ मानों का प्रबंधन कैसे आप खंड मैं के रूप में जुड़े हुए संशोधित हो सकता है इस प्रकार है: http://www.w3.org/TR:
// 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);
});
}
}
}
यहाँ क्लिपबोर्ड आइटम आप के साथ काम कर रहे हैं के लिए चश्मा हैं /2011/WD-html5-20110113/dnd.html#the-datatransferitem-interface। – pimvdb