clearData method
Removes one or more data formats from the clipboard through the dataTransfer object or the clipboardData object.
Syntax
object.clearData(format)Parameters
- format [in, optional]
-
Type: String
A String that specifies one or more of the following data format values.
Return value
Type: Boolean
A Boolean value indicating success or failure.Standards information
There are no standards that apply here.
Remarks
If no format parameter is passed, the data formats are cleared.
For drag-and-drop operations, the clearData method of the dataTransfer object is used generally in source events, such as ondragstart. When you override the default behavior of the target, use clearData in the ondrop event. It is particularly useful for selectively removing data formats when multiple formats are specified.
Examples
This example uses the clearData method to remove the Text data format from the clipboard through the dataTransfer object.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/clearDataEX.htm
<head>
<script type="text/javascript">
div {background-color:magenta; width: 300;}
span {color:lightgreen;}
</style>
<script type="text/javascript">
function Source_DragStart() {
event.dataTransfer.setData("Text", "This text will be cleared");
}
function Target_Enter() {
window.event.returnValue = false;
event.dataTransfer.clearData("Text");
oTarget.innerText = event.dataTransfer.getData("Text");
}
</script>
</head>
<body>
<p>Drag the green text and drop it over the magenta DIV.</p>
<span id="oSource" ondragstart="Source_DragStart()">
Drag this text.
</span>
<p>Drop the text below. The word "null" will appear in the DIV.</p>
<div
id="oTarget" ondragenter="Target_Enter()">
</div>
</body>
See also
- clipboardData
- dataTransfer
- Reference
- getData
- setData
- Conceptual
- About DHTML Data Transfer
Send comments about this topic to Microsoft
Build date: 11/28/2012