Methods


getData Method

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

Syntax

sRetrieveData = object.getData(sDataFormat)

Parameters

sDataFormat Required. 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

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 browser 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 browser 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.

<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 feature requires Microsoft Internet Explorer 5 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

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

<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>
This feature requires Microsoft Internet Explorer 5 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

There is no public standard that applies to this method.

Applies To

clipboardData, dataTransfer, DataTransfer Constructor

See Also

Tags :


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.)

Tags : contentbug?

Page view tracker