DHTML Methods
Specifies what data format and information to add to the system clipboard through the dataTransfer object.
window.dataTransfer.setData ( [ sDataFormat ]
[ , vHelperData ] )
sDataFormat |
Optional. Specifies the data format to add to the system clipboard using the dataTransfer object. This string value can be one of the following:
Text |
Default. Specifies that the data being transferred is text. |
URL |
Specifies that the data being transferred is a URL. | |
vHelperData |
Associates information with the object being dragged. This information can be descriptive text, a source path to an image, or a URL for an anchor. When URL is passed as the sDataFormat parameter, vHelperData must be used to provide the location of the object being transferred. |
No return value.
The setData parameters are not case-sensitive.
The example demonstrates how to use the setData and getData methods to create a shortcut to an image.
Sample Code
<head>
<script language="JavaScript">
var sImageURL;
function InitiateDrag ( ) {
// The setData parameters tell the source object
// to transfer data as a URL and provide the path.
window.dataTransfer.setData ( "URL", oImage.src );
}
function FinishDrag ( ) {
// The parameter passed to getData tells the target
// object what data format to expect.
sImageURL = window.dataTransfer.getData ( "URL" )
oTarget.innerText = sImageURL;
}
</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>
<IMAGE id=oImage src="black.gif"
ondragstart="InitiateDrag ( ) ">
<span id=oTarget ondragenter="FinishDrag ( ) ">
drop the image here</span>
</body>
Show me
dataTransfer
Data Transfer Overview, clearData, dropEffect, effectAllowed, getData