Adds data in a specified format to the DataTransfer object or the ClipboardData object.
Method of dom/DataTransferdom/DataTransfer
Syntax event.dataTransfer.setData(format, data);
Parameters format
The format of the data to be transferred, using one of the following values (case insensitve):
Specifies the data supplied by the source object. This information can be descriptive text, a source path to an image, or a URL for an anchor. When you pass “URL” as the format parameter, you must use the data parameter to provide the location of the object that is transferred.
Return ValueNo return value
ExamplesThis example uses the setData method and the getData method with the DataTransfer object to create a shortcut to an image.
<!doctype html>
<html>
<head>
<script>
var sImageURL, oTarget, oImage;
function initiateDrag(e) {
e.dataTransfer.setData("URL", oImage.src);
}
function finishDrag(e) {
sImageURL = e.dataTransfer.getData("URL");
oTarget.textContent = sImageURL;
}
function initialize() {
oImage = document.getElementById("oImage");
oTarget = document.getElementbyId("oTarget");
oImage.addEventListener("dragstart", initiateDrag, false);
oTarget.addEventListener("dragenter", finishDrag, false);
}
window.addEventListener("load", initialize, false);
</script>
</head>
<body>
<p>This example demonstrates how to use the setData and getData methods of the dataTransfer object to enable the source path of the image to be dragged.</p>
<img id="oImage" src="/workshop/graphics/black.png" width="20" height="20" alt="Black">
<span id="oTarget">
Drop the image here
</span>
</body>
</html>
Related specifications
Microsoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4