setData method (Internet Explorer)

Switch View :
ScriptFree
setData method

[This documentation is preliminary and is subject to change.]

Assigns data in a specified format to the dataTransfer object or the clipboardData object.

Syntax

object.setData(format, data)

Standards information

There are no standards that apply here.

Parameters

format [in]

Type: BSTR

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.

data [in]

Type: VARIANT

A Variant of type 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 format parameter, you must use the data parameter to provide the location of the object that is transferred.

Return value

Type: Boolean

Boolean. Returns one of the following possible values.

Return valueDescription
true

The data was successfully added.

false

The data was not added.

 

Remarks

The value of the format parameter is not case-sensitive.

Examples

This example uses the setData method and the getData method with the dataTransfer object to create a shortcut to an image.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/setDataEX.htm


<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="/workshop/graphics/black.png" 
       ondragstart="InitiateDrag()">
<SPAN ID=oTarget ondragenter="FinishDrag()">
    Drop the image here
</SPAN>
</BODY>

See also

clipboardData
dataTransfer
DataTransfer Constructor
Reference
clearData
getData
Conceptual
About DHTML Data Transfer

 

 

Build date: 2/14/2012

Community Content

rdubwest
setData failing on clipboardData
the following javascript is failing with a clipboard not available in IE8, it works fine with IE7 (pfidString is a string variable that has a non-null value)

bResul2=top.window.clipboardData.setData("Text",pfidString)

Alphapapalima
RegisterClipboardFormat
Is it possible to register a custom data format instead of "Text" and "Url". Can I define my own format?

John Sudds [Microsoft]
Possible Reasons for getData to fail
Does anyone know which Internet Explorer 6 settings could cause the getData on an clipboard object to fail?
We have a paste mechanism that works everywhere but at a specific client, the Method just returns false.
---
Make sure URLACTION_SCRIPT_PASTE ("Allow paste operations via script.") is set to Enable.