DHTML Methods
Removes one or more data formats from the dataTransfer object.
bDeleted=window.dataTransfer.clearData ( [ sDataFormat ] )
sDataFormat |
Optional. Specifies the data format to remove from the system clipboard using the dataTransfer object. All formats are cleared when no parameter is passed. This string value can be one of the following:
Text |
Causes the text format to be removed. |
URL |
Causes the URL format to be removed. |
File |
Causes the file format to be removed. |
HTML |
Causes the HTML format to be removed. |
Image |
Causes the Image format to be removed. |
|
Boolean. If a legal format is specified when that format is not present, the function returns false. Otherwise, the function returns true.
The clearData method of the dataTransfer object is generally used in source events, such as the ondragstart event. When overriding the default behavior of the target, use clearData in the ondrop event.
The example uses the clearData method to strip the text data format from the dataTransfer object.
Sample Code
<head>
<script language="JavaScript">
var sGetData;
function srcDragStart ( ) {
window.dataTransfer.setData ( "Text",
"This text should be cleared" );
}
function targetDrop ( ) {
window.dataTransfer.clearData ( "Text" );
sGetData = window.dataTransfer.getData ( "Text" );
theTarget.innerText = sGetData;
}
</script>
</head>
<body>
<p>Drag the green text and drop it over
the magenta <b>DIV</b>.</p>
<div align="center">
<span id="theSource" ondragstart="srcDragStart ( )">
drag this text</span>
<div id="theTarget" ondrop="targetDrop ( )"></div>
</div>
</body>
This feature requires Microsoft® Internet Explorer® 5 or later.
Show me
dataTransfer
Data Transfer Overview, getData, setData