HBCMS更多的中文手册参考:

getData Method

DHTML文档教程

Retrieves the data in the specified format from the clipboard through the datatransfer or clipboarddata objects.

dhtml语法

sretrievedata = object.getdata(sdataformat)

parameters

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

Examples

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.

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.

是否符合公共标准

There is no public standard that applies to this method.

Applies To

clipboardData, dataTransfer

更多语法参考

about dhtml data transfer, cleardata, setData