Export (0) Print
Expand All

getData method

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

Syntax

object.getData(format)

Parameters

format [in]

Type: String

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.

Standards information

There are no standards that apply here.

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 type="text/javascript">
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 type="text/javascript">
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

 

 

Show:
© 2014 Microsoft