Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

DataTransfer.effectAllowed — allowed drag operations

DataTransfer.effectAllowed specifies which operations the drag source permits. It does not select the final operation: dropEffect describes that operation and must agree with the allowed set.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

dataTransfer.effectAllowed
 dataTransfer.effectAllowed = "copyMove";

DataTransfer.effectAllowed is a string property of a browser interface, not an ECMAScript feature. During a drag, the source sets it in the dragstart handler, when the drag data store is in read/write mode. In other modes or with an invalid value, the assignment leaves the previous value unchanged.

Allowed values are none (no operation), copy, link, move, the pairs copyLink, copyMove, linkMove, plus all (all three) and uninitialized (the default state without an explicit restriction). Values are case-sensitive. A real drag starts with uninitialized.

dropEffect describes the selected operation, not the allowed set. A target typically cancels dragover using preventDefault() and sets a compatible dropEffect. A mismatch prevents the drop; effectAllowed alone does not copy or move application data.

In the verified Chromium run, the console shows that the standalone object created with new DataTransfer() remains at none after both the valid copyMove assignment and the invalid COPY assignment. This differs from the HTML Standard: an object created with new DataTransfer() has a drag data store in read/write mode, so the valid assignment should set effectAllowed to copyMove, and the subsequent invalid COPY assignment should leave it at copyMove. The console output shows what happened in that Chromium run, not how the setter is specified to behave across browsers.

When the user starts a drag, the dragstart handler sets copyMove on event.dataTransfer, and the subsequent COPY assignment leaves that value unchanged. The example targets browsers; Node 24 in a repository does not establish support for this API.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>DataTransfer.effectAllowed</title>
</head>
<body>
  <h1>Allowed drag operations</h1>
  <p id="source" draggable="true">Drag this text, then press Escape to cancel.</p>
  <p id="status" role="status">Start a drag to see which operations the source allows.</p>
  <script>
    const standalone = new DataTransfer();
    standalone.effectAllowed = 'copyMove';
    console.log('Standalone after copyMove: ' + standalone.effectAllowed);
    standalone.effectAllowed = 'COPY';
    console.log('Standalone after COPY: ' + standalone.effectAllowed);

    document.getElementById('source').addEventListener('dragstart', (event) => {
      const transfer = event.dataTransfer;
      transfer.setData('text/plain', 'Example drag');
      transfer.effectAllowed = 'copyMove';
      const accepted = transfer.effectAllowed;
      transfer.effectAllowed = 'COPY';
      document.getElementById('status').textContent =
        'Drag source after copyMove: ' + accepted +
        '. After invalid COPY: ' + transfer.effectAllowed + '.';
    });
  </script>
</body>
</html>

Result

Standalone after copyMove: none
Standalone after COPY: none

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources