JavaScript操作剪贴板 - ( for IE )
bRet = [window.]clipboardData.clearData(['Text' | 'URL' | 'File' | 'HTML' | 'Image'])
sData = [window.]clipboardData.getData('Text' | 'URL')
bAdded = [window.]clipboardData.setData('Text' | 'URL', sData)
下面为来自MSDN的内容:
参见:
http://msdn.microsoft.com/en-us/vstudio/ms536352%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/vstudio/ms536436%28v=VS.85%29
http://msdn.microsoft.com/en-us/vstudio/ms536744%28v=VS.85%29
clearData Method
Removes one or more data formats from the clipboard through the dataTransfer object or the clipboardData object.
Syntax
pret = object.clearData( [sDataFormat])
Parameters
sDataFormat Optional. A String that 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
A Boolean value indicating success or failure.
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 used generally in source events, such as ondragstart. When you override 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.
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 application 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 application 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.
setData Method
Assigns data in a specified format to the dataTransfer object or the clipboardData object.
Syntax
bSuccess = object.setData(sDataFormat, sData)
Parameters
sDataFormat Required. A String that 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. A String that 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 that is 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. |