clearData Method

DHTML, HTML, & CSS

clearData Method


Removes one or more data formats from the clipboard through dataTransfer or clipboardData object.

Syntax

object.clearData([sDataFormat])

Parameters

sDataFormatOptional. String that specifies one or more of the following data format values:
TextRemoves the text format.
URLRemoves the URL format.
FileRemoves the file format.
HTMLRemoves the HTML format.
ImageRemoves the image format.

Return Value

No return value.

Remarks

If no sDataFormat parameter is passed, the data formats are cleared.

For drag-and-drop operations, the clearData method of the dataTransfer object is generally used in source events, such as ondragstart. When overriding 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.

Example

This example uses the clearData method to remove the Text data format from the clipboard through the dataTransfer object.

Sample Code

<HEAD>
<STYLE>
DIV {background-color:magenta; width: 300;}
SPAN {color:lightgreen;}
</STYLE>

<SCRIPT>
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>

This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
clipboardData, dataTransfer

See Also

dhtml data transfer overviewInternet Link, getData, setData


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.