clearData method

Removes one or more data formats from the clipboard through the dataTransfer object. For the clipboardData object, this method clears all formats.

Syntax

object.clearData(format)

Parameters

format [in, optional]

Type: String

A String that specifies one or more of the following data format values to clear from a dataTransfer object.

Text

Removes the text format.

URL

Removes the URL format.

File

Removes the file format.

HTML

Removes the HTML format.

Image

Removes the image format.

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

 

 

Show:
© 2014 Microsoft. All rights reserved.