Click to Rate and Give Feedback
Properties
 effectAllowed Property
effectAllowed Property

Sets or gets which data transfer operations are allowed for the object on the source element.

Syntax

[ sEffect = ] dataTransfer.effectAllowed [ = v ]

Possible Values

sEffectString that specifies or receives one of the following values.
copySelection is copied.
linkSelection is linked to the drop target by the data transfer operation.
moveSelection is moved to the target location when dropped.
copyLinkSelection is copied or linked, depending on the target default.
copyMoveSelection is copied or moved, depending on the target default.
linkMoveSelection is linked or moved, depending on the target default.
allAll drop effects are supported.
noneDropping is disabled and the no-drop cursor is displayed.
uninitializedDefault. No value has been set through the effectAllowed property. In this case, the default effect still works, although it cannot be queried through this property.

The property is read/write. The property has a default value of uninitialized.

Remarks

Set the effectAllowed property in the ondragstart event. This property is used most effectively with the dropEffect property.

This property can be used to override the default behavior in other applications. For example, the browser script can set the effectAllowed property to copy for a text field and override the Microsoft Word default of move. In the browser, copy is the default effectAllowed behavior; however, anchors are set to link by default, and text fields are set to move by default.

By setting effectAllowed to none, dropping is disabled but the no-drop cursor is still displayed. To avoid displaying the no-drop cursor, cancel the returnValue of the ondragstart window.

Example

This example uses the dropEffect property and the effectAllowed property to move text in a drag-and-drop operation.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Example of the effectAllowed and dropEffect Properties</TITLE>

<SCRIPT>
// This function is called when the user 
//  initiates a drag-and-drop operation.
function fnHandleDragStart()
{                                      
  var oData = window.event.dataTransfer;

  // Set the effectAllowed on the source object.
  oData.effectAllowed = "move";
}

// This function is called by the target 
//  object in the ondrop event.
function fnHandleDrop()
{
  var oTarg = window.event.srcElement;
  var oData = window.event.dataTransfer;

  // Cancel default action.
  fnCancelDefault();

  // Set the content of the oTarget to the information stored
  //  in the data transfer object in the desired format.
  oTarg.innerText += oData.getData("text");
}

// This function sets the dropEffect when the user moves the 
//  mouse over the target object.
function fnHandleDragEnter()
{
  var oData = window.event.dataTransfer;

  // Cancel default action.
  fnCancelDefault();

  // Set the dropEffect for the target object.
  oData.dropEffect = "move";
}

function fnCancelDefault()
{
  // Cancel default action.
  var oEvent = window.event;
  oEvent.returnValue = false;
}
</SCRIPT>

</HEAD>

<BODY>
<H1>Example of the effectAllowed and dropEffect Properties</H1>

<P>The code in this example sets the <B>effectAllowed</B> property 
to <SPAN CLASS="literal">move</SPAN>. It sets the <B>dropEffect</B> 
property to display the move cursor. The default action must be 
canceled in all events that are handled&#151;in this example, 
<B>ondragstart</B>, <B>ondragover</B>, <B>ondragenter</B>, and 
<B>ondrop</B>.</P>
<B>
  [not this text]
<SPAN ID="oSource" ondragstart="fnHandleDragStart()">
  [select and drag this text]
</SPAN>
  [not this text]
</B>
<P><BR><P>
<DIV ID="oTarget" 
     STYLE="background:beige; 
            height:100;
            width:200;
            border:solid black 1px;"
     ondrop="fnHandleDrop()"
     ondragover="fnCancelDefault()"
     ondragenter="fnHandleDragEnter()">
[drop text here]
</DIV>
</BODY>
</HTML>
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 property.

Applies To

dataTransfer

See Also

About DHTML Data Transfer, clearData, getData, setData
Tags What's this?: Add a tag
Community Content
 
Add Community Content
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker