setData method
Assigns data in a specified format to the dataTransfer object or the clipboardData object.
Syntax
object.setData(format, data)Parameters
- format [in]
-
Type: String
A String that specifies the format of the data to be transferred, using one of the following values.
- data [in]
-
Type: Variant
A Variant of type String that 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 value
Type: Boolean
Boolean. Returns one of the following possible values.
| Return value | Description |
|---|---|
|
The data was successfully added. |
|
The data was not added. |
Standards information
There are no standards that apply here.
Remarks
The value of the format parameter is not case-sensitive.
Examples
This example uses the setData method and the getData method with the dataTransfer object to create a shortcut to an image.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/setDataEX.htm
<HEAD>
<SCRIPT>
var sImageURL;
function InitiateDrag()
/* The setData parameters tell the source object
to transfer data as a URL and provide the path. */
{
event.dataTransfer.setData("URL", oImage.src);
}
function FinishDrag()
/* The parameter passed to getData tells the target
object what data format to expect. */
{
sImageURL = event.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="/workshop/graphics/black.png"
ondragstart="InitiateDrag()">
<SPAN ID=oTarget ondragenter="FinishDrag()">
Drop the image here
</SPAN>
</BODY>
See also
- clipboardData
- dataTransfer
- Reference
- clearData
- getData
- Conceptual
- About DHTML Data Transfer
Send comments about this topic to Microsoft
Build date: 11/27/2012
