www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
Methods
 setData Method
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.
TextTransfers data formatted as text.
URLTransfers 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.

trueThe data was successfully added.
falseThe data was not added.

Remarks

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

Example

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

<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" 
       >

<SPAN ID=oTarget >
    Drop the image 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.

Standards Information

There is no public standard that applies to this method.

Applies To

clipboardData, dataTransfer

See Also

About DHTML Data Transfer, clearData, getData
Tags What's this?: Add a tag
Community Content
 
Add Community Content
Possible Reasons for getData to fail      JensK1977 ... John Sudds - MSFT   |   Edit   |  
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.
Tags What's this?: dhtml (x) Add a tag
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG