getData method (Internet Explorer)

Switch View :
ScriptFree
getData method

[This documentation is preliminary and is subject to change.]

Gets the data in the specified format from the clipboard through the dataTransfer object or the clipboardData object.

Syntax

object.getData(format)

Standards information

There are no standards that apply here.

Parameters

format [in]

Type: BSTR

A String that specifies one of the following data format values.

Text

Gets data formatted as text.

URL

Gets data formatted as a URL.

Return value

Type: Variant

Variant of type String. Returns the data in the format retrieved from the clipboard through the dataTransfer object or the clipboardData object. Depending on the information contained in setData, this variable can get a path to an image, text, or an anchor URL.

Remarks

The getData method enforces cross-frame security and allows data transfers only in the same domain. To the user, this means that a selection that is dragged between different security protocols, such as HTTP and HTTPS, fails. In addition, that a selection that is dragged between two instances of the application with different security levels, where the first instance is set to medium and the second is set to high, fails. Finally, that a selection that is dragged into the application from another drag-enabled application, such as Microsoft Word, also fails.

To use the getData method to get data from the clipboard in the oncopy event or the oncut event, specify window.event.returnValue=false in the event handler script.

Examples

The following examples use the setData method and the getData method of the dataTransfer object to drop text in a new location and create a desktop shortcut.

This example uses the getData method to drag text and drop it in a new location.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/getDataEX.htm


<HEAD>
<SCRIPT>
function InitiateDrag(){
  event.dataTransfer.setData(oSource.innerText);
}
function FinishDrag(){
  window.event.returnValue=false;
  oTarget.innerText = event.dataTransfer.getData("Text");
}
function OverDrag(){
  window.event.returnValue=false;
}
</SCRIPT>
</HEAD>
<BODY>
<B ID="oSource"
   ondragstart="InitiateDrag()">
drag this text</B>
<SPAN ID="oTarget"
   ondragover="OverDrag()"
   ondragenter="FinishDrag()"">
drop text here</SPAN>
</BODY>

This example uses the getData method to create a desktop shortcut using a drag-and-drop operation.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/obj_dataTransferEX.htm


<HEAD>
<SCRIPT>
function InitiateDrag(){   
  event.dataTransfer.setData("URL", oSource.href);
}
function FinishDrag(){
  oTarget.innerText = event.dataTransfer.getData("URL");
}
</SCRIPT>
</HEAD>
<BODY>
<A ID=oSource HREF="about:Example_Complete" 
   onclick="return(false)" ondragstart="InitiateDrag()">Test Anchor</A>
<SPAN ID=oTarget ondrop="FinishDrag()">Drop Here</SPAN>
</BODY>

See also

clipboardData
dataTransfer
Reference
clearData
setData
Conceptual
About DHTML Data Transfer

 

 

Build date: 3/8/2012

Community Content

Mr. Raymond Kenneth Petry
Limitations - underlying HTML - inaccessible

The clipboard underlying HTML is lost by getData() which is text-only....

PROPOSAL: Have, sDataFormat='HTML' or ="rich' (subset), include cssText of HTML-copy and P, SPAN, FONT, ?xml, o:p,-elements of RTF-copy, without the 13x loading-time.

(N.B. This does-not affect Copy-Paste nor Drag-Drop, which keep their underlying HTML.)