下面的表格列出了 clipboardData 对象引出的成员。请单击左侧的标签来选择你想要查看的成员类型。
方法:
方法 | 描述 |
---|---|
clearData | 通过 dataTransfer 或 clipboardData 对象从剪贴板删除一种或多种数据格式。 |
getData | 通过 dataTransfer 或 clipboardData 对象从剪贴板获取指定格式的数据。 |
setData | 以指定格式给 dataTransfer 或 clipboardData 对象赋予数据。 |
clearData Method | Internet Development Index |
Removes one or more data formats from the clipboard through dataTransfer or clipboardData object.
Syntax
pret = object.clearData( [sDataFormat])
Parameters
sDataFormat Optional. Stringthat specifies one or more of the following data format values:
Text Removes the text format. URL Removes the URL format. File Removes the file format. HTML Removes the HTML format. Image Removes the image format.
Return Value
No return value.
Remarks
If no sDataFormat parameter is passed, the data formats are cleared.
For drag-and-drop operations, the clearData method of the dataTransfer object is generally used in source events, such as ondragstart. When overriding the default behavior of the target, use clearData in the ondrop event. It is particularly useful for selectively removing data formats when multiple formats are specified.
Example
This example uses the clearData method to remove the Text data format from the clipboard through the dataTransfer object.
SHOWExample
<HEAD> <STYLE> DIV {background-color:magenta; width: 300;} SPAN {color:lightgreen;} </STYLE> <SCRIPT> function Source_DragStart(){ event.dataTransfer.setData("Text", "This text will be cleared"); } function Target_Enter(){ window.event.returnValue = false; event.dataTransfer.clearData("Text"); oTarget.innerText = event.dataTransfer.getData("Text"); } </SCRIPT> </HEAD> <BODY> <P>Drag the green text and drop it over the magenta DIV.</P> <SPAN ID="oSource" οndragstart="Source_DragStart()"> Drag this text. </SPAN> <P>Drop the text below. The word "null" will appear in the DIV.</P> <DIV ID="oTarget" οndragenter="Target_Enter()"> </DIV> </BODY>
Standards Information
There is no public standard that applies to this method.
Applies To
[ Object Name ] Platform Version Win16: Win32: Unix: Mac: Windows CE: Version data is listed when the mouse hovers over a link, or the link has focus. clipboardData, dataTransfer Move the mouse pointer over an element in the Applies To list to display availability information for the listed platforms.
See Also
About DHTML Data Transfer, getData, setData
getData Method
Internet Development Index
Retrieves the data in the specified format from the clipboard through the dataTransfer or clipboardData objects.
Syntax
sRetrieveData = object.getData(sDataFormat)
Parameters
sDataFormat Required. Stringthat specifies one of the following data format values:
Text Retrieves data formatted as text. URL Retrieves 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.
SHOWExample
<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" οndragstart="InitiateDrag()"> drag this text</B> <SPAN ID="oTarget" οndragοver="OverDrag()" οndragenter="FinishDrag()""> drop text here</SPAN> </BODY>This example uses the getData method to create a desktop shortcut using a drag-and-drop operation.
SHOWExample
<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" οnclick="return(false)" οndragstart="InitiateDrag()">Test Anchor</A> <SPAN ID=oTarget οndrοp="FinishDrag()">Drop Here</SPAN> </BODY>Standards Information
There is no public standard that applies to this method.
Applies To
[ Object Name ] Platform Version Win16: Win32: Unix: Mac: Windows CE: Version data is listed when the mouse hovers over a link, or the link has focus. clipboardData, dataTransfer Move the mouse pointer over an element in the Applies To list to display availability information for the listed platforms. See Also
About DHTML Data Transfer, clearData, setData
setData Method
Internet Development Index
Assigns data in a specified format to the dataTransfer or clipboardData object.
Syntax
bSuccess = object.setData(sDataFormat, sData)
Parameters
sDataFormat Required. Stringthat specifies the format of the data to be transferred, using one of the following values:
Text Transfers data formatted as text. URL Transfers data formatted as a URL. sData Required. Stringthat specifies the data supplied by the source object. This information can be descriptive text, a source path to an image, or a URL for an anchor. When you pass "URL" as the sDataFormat parameter, you must use the sData parameter to provide the location of the object being transferred. Return Value
Boolean. Returns one of the following possible values:
true The data was successfully added. false The data was not added. Remarks
The value of the sDataFormat parameter is not case-sensitive.
Example
This example uses the setData and getData methods with the dataTransfer object to create a shortcut to an image.
SHOWExample
<HEAD> <SCRIPT> var sImageURL; function InitiateDrag() /* The setData parameters tell the source object to transfer data as a URL and provide the path. */ { event.dataTransfer.setData("URL", oImage.src); } function FinishDrag() /* The parameter passed to getData tells the target object what data format to expect. */ { sImageURL = event.dataTransfer.getData("URL") oTarget.innerText = sImageURL; } </SCRIPT> </HEAD> <BODY> <P>This example demonstrates how to use the setData and getData methods of the dataTransfer object to enable the source path of the image to be dragged.</P> <IMAGE ID=oImage SRC="../common/black.gif" οndragstart="InitiateDrag()"> <SPAN ID=oTarget οndragenter="FinishDrag()"> Drop the image here </SPAN> </BODY>Standards Information
There is no public standard that applies to this method.
Applies To
dataTransfer Platform Version Win16: 5 Win32: 5 Unix: 5 Mac: 5 Windows CE: 5.5 Version data is listed when the mouse hovers over a link, or the link has focus. clipboardData, dataTransfer Move the mouse pointer over an element in the Applies To list to display availability information for the listed platforms. See Also
About DHTML Data Transfer, clearData, getData