dataTransfer.clearData() (Method)

Clears any data currently in the transfer object.


JScript - 5.0
Internet Explorer - 5.0
JavaScript syntax:IEmyDataTransfer.clearData()

The contents of the dataTransfer object are discarded according to the values specified. To understand what this means requires a short discussion about clipboards and how they work.

The Microsoft Windows clipboard is modelled very closely on the clipboard mechanisms originally implemented in the Macintosh operating system in 1984, when it was first released. The Macintosh environment is constructed around a set of resource objects. When a selection is cut or copied to the clipboard, what is actually stored is a set of resources that describe the selection in a variety of different ways. This enables the target application that receives a paste command to select the most appropriate piece of data that it can understand.

For example, in a music application, the selected region of notation is copied to the clipboard as the following:

If you then go to a word processor and paste in the clipping, it won't understand the MIDI data or the application specific data. However, it could very well understand the picture data and would choose that as being the most appropriate.

This explains how data is lost when you cut and paste between several applications and back to the originating application. Some applications are quite good at preserving the entire contents of the clipboard even though they may only understand one of its component varieties. An example of that is the Macintosh Scrapbook application. It can only display a picture when music clippings are pasted in from a MIDI sequencer. However, it preserves all the component resources and if you copy an item from the scrapbook, you get the complete set again.

Going back to the MSIE browser and the dataTransfer object, the drag drop and clipboard mechanism carries a collection of related resources. Each is a copy of the source item in different forms. This clearData() method can be used to discard the forms that you no longer need.

It accepts the following values in its argument:

You can specify one or several of these to discard the values you no longer need.

This method should be called in an onDragStart event handler for maximum effect. If you need to override the default behavior of the target receiver, then you may want to use this in the onDrop event handler too.

See also:clipboardData object, onDragStart, onDrop