aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/api/datatransfer/index.html
blob: 01c9ba4fbf696293e1c730992094a0d2ea61d3a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
---
title: DataTransfer
slug: Web/API/DataTransfer
translation_of: Web/API/DataTransfer
---
<div>{{APIRef("HTML DOM")}}</div>

<p>{{ gecko_minversion_header("1.9") }} El objeto <code>DataTransfer</code> es usado como contenedor de datos que estan siendo manipulados durante la operación de drag and drop. Este puede contener uno o varios objetos, de uno o varios tipos de datos. Para más información  en cuanto a drag and drop, ver <a class="internal" href="/En/DragDrop/Drag_and_Drop" title="En/DragDrop/Drag and Drop">Drag and Drop</a>.</p>

<p>Este objeto esta disponible desde la propiedad <code>dataTransfer</code> de todos los eventos de drag . No pueden ser creados por separado.</p>

<h2 id="Properties" name="Properties">Lista de propiedades</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <td class="header">Properties</td>
   <td class="header">Type</td>
  </tr>
  <tr>
   <td><code><a href="#dropEffect.28.29" title="En/DragDrop/DataTransfer#dropEffect">dropEffect</a></code></td>
   <td><code><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String" title="en/String">String</a></code></td>
  </tr>
  <tr>
   <td><code><a href="#effectAllowed.28.29" title="En/DragDrop/DataTransfer#effectAllowed">effectAllowed</a></code></td>
   <td><code><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String" title="en/String">String</a></code></td>
  </tr>
  <tr>
   <td><a href="#files.28.29" title="En/DragDrop/DataTransfer#files"><code>files</code></a> {{ gecko_minversion_inline("1.9.2") }}</td>
   <td>{{ domxref("FileList") }}</td>
  </tr>
  <tr>
   <td><code><a href="#mozCursor" title="En/DragDrop/DataTransfer#mozCursor">mozCursor</a></code> {{ non-standard_inline() }} {{ gecko_minversion_inline("1.9.1") }}</td>
   <td><code><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String" title="en/String">String</a></code></td>
  </tr>
  <tr>
   <td><code><a href="#mozItemCount.28.29" title="En/DragDrop/DataTransfer#mozItemCount">mozItemCount</a></code> {{ non-standard_inline() }}</td>
   <td><code>unsigned long</code></td>
  </tr>
  <tr>
   <td><a href="#mozSourceNode" title="En/DragDrop/DataTransfer#mozSourceNode"><code>mozSourceNode</code></a> {{ non-standard_inline() }} {{ gecko_minversion_inline("2") }}</td>
   <td>{{ domxref("Node") }}</td>
  </tr>
  <tr>
   <td><a href="#mozUserCancelled" title="En/DragDrop/DataTransfer#mozUserCancelled"><code>mozUserCancelled</code></a></td>
   <td><a href="/en/JavaScript/Reference/Global_Objects/Boolean" title="en/Core JavaScript 1.5 Reference/Global Objects/Boolean"><code>Boolean</code></a></td>
  </tr>
  <tr>
   <td><code><a href="#types.28.29" title="En/DragDrop/DataTransfer#types">types</a></code></td>
   <td><code><a href="/en-US/docs/Web/API/DOMStringList" title="en-US/docs/Web/API/DOMStringList">DOMStringList</a></code></td>
  </tr>
 </tbody>
</table>

<h2 id="Method_overview" name="Method_overview">Lista de métodos</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <td><code>void <a href="#addElement.28.29">addElement</a>(in <a href="/en/XPCOM_Interface_Reference/nsIDOMElement" title="en/nsIDOMElement">Element</a> element)</code></td>
  </tr>
  <tr>
   <td><code>void <a href="#clearData.28.29">clearData</a>([in <a href="/en/String" title="en/String">String</a> type])</code></td>
  </tr>
  <tr>
   <td><code><a href="/en/String" title="en/String">String</a> <a href="#getData.28.29">getData</a>(in <a href="/en/String" title="en/String">String</a> type)</code></td>
  </tr>
  <tr>
   <td><code>void <a href="#setData.28.29">setData</a>(in <a href="/en/String" title="en/String">String</a> type, in <a href="/en/String" title="en/String">String</a> data)</code></td>
  </tr>
  <tr>
   <td><code>void <a href="#setDragImage.28.29">setDragImage</a>(in <a href="/en/XPCOM_Interface_Reference/nsIDOMElement" title="en/nsIDOMElement">nsIDOMElement</a> image, in long x, in long y)</code></td>
  </tr>
  <tr>
   <td><code>void <a href="#mozClearDataAt.28.29">mozClearDataAt</a>([in <a href="/en/String" title="en/String">String</a> type, in unsigned long index])</code></td>
  </tr>
  <tr>
   <td><code><a href="/en/XPCOM_Interface_Reference/NsIVariant" title="en/nsIVariant">nsIVariant</a> <a href="#mozGetDataAt.28.29">mozGetDataAt</a>(in <a href="/en/String" title="en/String">String</a> type, in unsigned long index)</code></td>
  </tr>
  <tr>
   <td><code>void <a href="#mozSetDataAt.28.29">mozSetDataAt</a>(in <a href="/en/String" title="en/String">String</a> type, in <a href="/en/XPCOM_Interface_Reference/NsIVariant" title="en/nsIVariant">nsIVariant</a> data, in unsigned long index)</code></td>
  </tr>
  <tr>
   <td><code><a href="/en/StringList" title="en/StringList">StringList</a> <a href="#mozTypesAt.28.29">mozTypesAt</a>([in unsigned long index])</code></td>
  </tr>
 </tbody>
</table>

<h2 id="Properties" name="Properties">Propiedades</h2>

<h3 id="dropEffect.28.29" name="dropEffect.28.29">dropEffect</h3>

<p>The actual effect that will be used, and should always be one of the possible values of <code>effectAllowed</code>.</p>

<p>For the <code>dragenter</code> and <code>dragover</code> events, the <code>dropEffect</code> will be initialized based on what action the user is requesting. How this is determined is platform specific, but typically the user can press modifier keys to adjust which action is desired. Within an event handler for the <code>dragenter</code> and <code>dragover</code> events, the <code>dropEffect</code> should be modified if the action the user is requesting is not the one that is desired.</p>

<p>For <code>dragstart</code>, <code>drag</code>, and <code>dragleave</code> events, the <code>dropEffect</code> is initialized to "none". Any value assigned to the <code>dropEffect</code> will be set, but the value isn't used for anything.</p>

<p>For the <code>drop</code> and <code>dragend</code> events, the <code>dropEffect</code> will be initialized to the action that was desired, which will be the value that the <code>dropEffect</code> had after the last <code>dragenter</code> or <code>dragover</code> event.</p>

<p>Possible values:</p>

<ul>
 <li><strong>copy</strong>: A copy of the source item is made at the new location.</li>
 <li><strong>move</strong>: An item is moved to a new location.</li>
 <li><strong>link</strong>: A link is established to the source at the new location.</li>
 <li><strong>none</strong>: The item may not be dropped.</li>
</ul>

<p>Assigning any other value has no effect and retains the old value.</p>

<h3 id="effectAllowed.28.29" name="effectAllowed.28.29">effectAllowed</h3>

<p>Specifies the effects that are allowed for this drag. You may set this in the <code>dragstart</code> event to set the desired effects for the source, and within the <code>dragenter</code> and <code>dragover</code> events to set the desired effects for the target. The value is not used for other events.</p>

<p>Possible values:</p>

<ul>
 <li><strong>copy</strong>: A copy of the source item may be made at the new location.</li>
 <li><strong>move</strong>: An item may be moved to a new location.</li>
 <li><strong>link</strong>: A link may be established to the source at the new location.</li>
 <li><strong>copyLink</strong>: A copy or link operation is permitted.</li>
 <li><strong>copyMove</strong>: A copy or move operation is permitted.</li>
 <li><strong>linkMove</strong>: A link or move operation is permitted.</li>
 <li><strong>all</strong>: All operations are permitted.</li>
 <li><strong>none</strong>: the item may not be dropped.</li>
 <li><strong>uninitialized</strong>: the default value when the effect has not been set, equivalent to all.</li>
</ul>

<p>Assigning any other value has no effect and retains the old value.</p>

<h3 id="files.28.29" name="files.28.29">files</h3>

<p>{{ gecko_minversion_header("1.9.2") }}</p>

<p>Contains a list of all the local files available on the data transfer. If the drag operation doesn't involve dragging files, this property is an empty list. An invalid index access on the {{ domxref("FileList") }} specified by this property will return <code>null</code>.</p>

<h4 id="Example">Example</h4>

<p>This example dumps the list of files dragged into the browser window: <a class="external" href="http://jsfiddle.net/9C2EF/" title="http://jsfiddle.net/9C2EF/">http://jsfiddle.net/9C2EF/</a></p>

<h3 id="types.28.29" name="types.28.29">types</h3>

<p>Holds a list of the format types of the data that is stored for the first item, in the same order the data was added. An empty list will be returned if no data was added.</p>

<p>{{ h3_gecko_minversion("mozCursor", "1.9.1", "mozCursor") }}</p>

<p>The drag cursor's state. This is primarily used to control the cursor during tab drags.</p>

<div class="note"><strong>Note:</strong> This method is currently only implemented on Windows.</div>

<h4 id="Possible_values">Possible values</h4>

<dl>
 <dt><code>auto</code></dt>
 <dd>Uses the default system behavior.</dd>
 <dt><code>default</code></dt>
 <dd>Uses the default Gecko behavior, which is to set the cursor to an arrow during the drag operation.</dd>
</dl>

<div class="note"><strong>Note:</strong> If you specify any value other than "default", "auto" is assumed.</div>

<h3 id="mozItemCount.28.29" name="mozItemCount.28.29">mozItemCount</h3>

<p>The number of items being dragged.</p>

<div class="note"><strong>Note:</strong> This property is Gecko-specific.</div>

<h3 id="mozSourceNode">mozSourceNode</h3>

<p>{{ gecko_minversion_header("2") }}</p>

<p>The {{ domxref("Node") }} over which the mouse cursor was located when the button was pressed to initiate the drag operation. This value is <code>null</code> for external drags or if the caller can't access the node.</p>

<div class="note"><strong>Note:</strong> This property is Gecko-specific.</div>

<h3 id="mozItemCount.28.29" name="mozItemCount.28.29">mozUserCancelled</h3>

<p>This property applies only to the <code>dragend</code> event, and is <code>true</code> if the user canceled the drag operation by pressing escape. It will be <code>false</code> in all other cases, including if the drag failed for any other reason, for instance due to a drop over an invalid location. This property is not currently implemented on Linux.</p>

<div class="note"><strong>Note:</strong> This property is Gecko-specific.</div>

<h2 id="Methods" name="Methods">Métodos</h2>

<h3 id="addElement.28.29" name="addElement.28.29">addElement()</h3>

<p>Set the drag source. Usually you would not change this, but it will affect which node the drag and dragend events are fired at. The default target is the node that was dragged.</p>

<pre class="eval"> void addElement(
   in Element element
 );
</pre>

<h6 id="Parameters_addElement" name="Parameters_addElement">Parameters</h6>

<dl>
 <dt><code>element </code></dt>
 <dd>The element to add.</dd>
</dl>

<h3 id="clearData.28.29" name="clearData.28.29">clearData()</h3>

<p>Remove the data associated with a given type. The type argument is optional. If the type is empty or not specified, the data associated with all types is removed. If data for the specified type does not exist, or the data transfer contains no data, this method will have no effect.</p>

<pre class="eval"> void clearData(
   [optional] in String type
 );
</pre>

<h6 id="Parameters_clearData" name="Parameters_clearData">Parameters</h6>

<dl>
 <dt><code>type </code></dt>
 <dd>The type of data to remove.</dd>
</dl>

<h3 id="getData.28.29" name="getData.28.29">getData()</h3>

<p>Retrieves the data for a given type, or an empty string if data for that type does not exist or the data transfer contains no data.</p>

<p>A security error will occur if you attempt to retrieve data during a drag that was set from a different domain, or the caller would otherwise not have access to. This data will only be available once a drop occurs during the drop event.</p>

<pre class="eval"> String getData(
   in String type
 );
</pre>

<h6 id="Parameters_getData" name="Parameters_getData">Parameters</h6>

<dl>
 <dt><code>type </code></dt>
 <dd>The type of data to retrieve.</dd>
</dl>

<h3 id="setData.28.29" name="setData.28.29">setData()</h3>

<p>Set the data for a given type. If data for the type does not exist, it is added at the end, such that the last item in the types list will be the new format. If data for the type already exists, the existing data is replaced in the same position. That is, the order of the types list is not changed when replacing data of the same type.</p>

<pre class="eval"> void setData(
   in String type,
   in String data
 );
</pre>

<h6 id="Parameters_setData" name="Parameters_setData">Parameters</h6>

<dl>
 <dt><code>type </code></dt>
 <dd>The type of data to add.</dd>
 <dt><code>data </code></dt>
 <dd>The data to add.</dd>
</dl>

<h3 id="setDragImage.28.29" name="setDragImage.28.29">setDragImage()</h3>

<p>Set the image to be used for dragging if a custom one is desired. Most of the time, this would not be set, as a default image is created from the node that was dragged.</p>

<p>If the node is an HTML img element, an HTML canvas element or a XUL image element, the image data is used. Otherwise, image should be a visible node and the drag image will be created from this. If image is null, any custom drag image is cleared and the default is used instead.</p>

<p>The coordinates specify the offset into the image where the mouse cursor should be. To center the image, for instance, use values that are half the width and height of the image.</p>

<pre class="eval"> void setDragImage(
   in Element image,
   in long x,
   in long y
 );
</pre>

<h6 id="Parameters_setDragImage" name="Parameters_setDragImage">Parameters</h6>

<dl>
 <dt><code>image </code></dt>
 <dd>An element to use as the drag feedback image</dd>
 <dt><code>x </code></dt>
 <dd>Horizontal offset within the image.</dd>
 <dt><code>y </code></dt>
 <dd>Vertical offset within the image.</dd>
</dl>

<h3 id="mozClearDataAt.28.29" name="mozClearDataAt.28.29">mozClearDataAt()</h3>

<p>Removes the data associated with the given format for an item at the specified index. The index is in the range from zero to the number of items minus one.</p>

<p>If the last format for the item is removed, the entire item is removed, reducing <code>mozItemCount</code> by one.</p>

<p>If the <code>format</code> list is empty, then the data associated with all formats is removed. If the format is not found, then this method has no effect.</p>

<div class="note"><strong>Note:</strong> This method is Gecko-specific.</div>

<pre class="eval"> void mozClearDataAt(
   [optional] in String type,
   in unsigned long index
 );
</pre>

<h6 id="Parameters_mozClearDataAt" name="Parameters_mozClearDataAt">Parameters</h6>

<dl>
 <dt><code>type </code></dt>
 <dd>The type of data to remove.</dd>
 <dt><code>index </code></dt>
 <dd>The index of the data to remove.</dd>
</dl>

<h3 id="mozGetDataAt.28.29" name="mozGetDataAt.28.29">mozGetDataAt()</h3>

<p>Retrieves the data associated with the given format for an item at the specified index, or null if it does not exist. The index should be in the range from zero to the number of items minus one.</p>

<div class="note"><strong>Note:</strong> This method is Gecko-specific.</div>

<pre class="eval"> nsIVariant mozGetDataAt(
   [optional] in String type,
   in unsigned long index
 );
</pre>

<h6 id="Parameters_mozClearDataAt" name="Parameters_mozClearDataAt">Parameters</h6>

<dl>
 <dt><code>type </code></dt>
 <dd>The type of data to retrieve.</dd>
 <dt><code>index </code></dt>
 <dd>The index of the data to retrieve.</dd>
</dl>

<h3 id="mozSetDataAt.28.29" name="mozSetDataAt.28.29">mozSetDataAt()</h3>

<p>A data transfer may store multiple items, each at a given zero-based index. <code>mozSetDataAt()</code> may only be called with an index argument less than <code>mozItemCount</code> in which case an existing item is modified, or equal to <code>mozItemCount</code> in which case a new item is added, and the <code>mozItemCount</code> is incremented by one.</p>

<p>Data should be added in order of preference, with the most specific format added first and the least specific format added last. If data of the given format already exists, it is replaced in the same position as the old data.</p>

<p>The data should be either a string, a primitive boolean or number type (which will be converted into a string) or an {{ interface("nsISupports") }}.</p>

<div class="note"><strong>Note:</strong> This method is Gecko-specific.</div>

<pre class="eval"> void mozSetDataAt(
   [optional] in String type,
   in nsIVariant data,
   in unsigned long index
 );
</pre>

<h6 id="Parameters_mozSetDataAt" name="Parameters_mozSetDataAt">Parameters</h6>

<dl>
 <dt><code>type </code></dt>
 <dd>The type of data to add.</dd>
 <dt><code>data </code></dt>
 <dd>The data to add.</dd>
 <dt><code>index </code></dt>
 <dd>The index of the data to add.</dd>
</dl>

<h3 id="mozTypesAt.28.29" name="mozTypesAt.28.29">mozTypesAt()</h3>

<p>Holds a list of the format types of the data that is stored for an item at the specified index. If the index is not in the range from 0 to the number of items minus one, an empty string list is returned.</p>

<div class="note"><strong>Note:</strong> This method is Gecko-specific.</div>

<pre class="eval"> nsIVariant mozTypesAt(
   in unsigned long index
 );
</pre>

<h6 id="Parameters_mozTypesAt" name="Parameters_mozTypesAt">Parameters</h6>

<dl>
 <dt><code>index </code></dt>
 <dd>The index of the data for which to retrieve the types.</dd>
</dl>

<h2 id="See_also" name="See_also">Mira también</h2>

<p><a class="internal" href="/En/DragDrop/Drag_and_Drop" title="Drag and Drop">Drag and Drop</a></p>

<p>{{ languages( { "ja": "Ja/DragDrop/DataTransfer" } ) }}</p>