getData Method

MS Office DHTML, HTML & CSS

getData Method


Retrieves the data in the specified format from the clipboard through the dataTransfer or clipboardData objects.

Syntax

sRetrieveData = object.getData(sDataFormat)

Parameters

sDataFormatRequired. String that specifies one of the following data format values:
TextRetrieves data formatted as text.
URLRetrieves data formatted as a URL.

Return Value

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

Remarks

The getData method enforces cross-frame security and allows data transfers within the same domain only. To the user this means that dragging a selection between different security protocols, such as HTTP and HTTPS, will fail. In addition, dragging a selection 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, will fail. Finally, dragging a selection into the browser from another drag-enabled application, such as Microsoft® Word, also will fail.

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

Example

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

Sample Code

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

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 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, clearData, 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.