setData Method

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
setCapture Method     setEndPoint Method     DHTML Methods    

setData Method


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

Syntax

bSuccess = object.setData(sDataFormat, sData)

Parameters

sDataFormatRequired. String that specifies the format of the data to be transferred, using one of the following values:
TextTransfers data formatted as text.
URLTransfers data formatted as a URL.
sDataRequired. 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 sData to provide the location of the object being transferred.

Return Value

Boolean. Returns true if the data was successfully added, or false otherwise.

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.

Sample Code

<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.gif" 
       ondragstart="InitiateDrag()">

<SPAN ID=oTarget ondragenter="FinishDrag()">
    Drop the image here
</SPAN>

</BODY>
This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
clipboardData, dataTransfer

See Also

data transfer overviewInternet Link, clearData, getData


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.