www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
Methods
 getData Method
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.
TextGets data formatted as text.
URLGets 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"
   >
drag this text</B>

<SPAN ID="oTarget"
   
   ">
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" 
    >Test Anchor</A>

<SPAN ID=oTarget >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

See Also

About DHTML Data Transfer, clearData, setData
Tags What's this?: Add a tag
Community Content
 
Add Community Content
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG