aboutsummaryrefslogtreecommitdiff
path: root/files/it/web/api/datatransfer/getdata/index.html
blob: 635da432ede9115e4ff36ee2377dbb0ed0ef1ae1 (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
---
title: DataTransfer.getData()
slug: Web/API/DataTransfer/getData
translation_of: Web/API/DataTransfer/getData
---
<div>
<p> </p>
{{APIRef("HTML DOM")}}</div>

<p>Il metodo <strong><code>DataTransfer.getData()</code></strong> recupera i dati del trascinamento  (come {{domxref("DOMString")}}) per il <em>data type</em> specificato. Se l'operazione di trascinamento non include dati, questo metodo restituisce una stringa vuota.</p>

<p>Esempi di tipi di <em>data types</em> sono <em><code>text/plain</code></em><em><code>text/uri-list</code></em>.</p>

<h2 id="Sintassi">Sintassi</h2>

<pre class="syntaxbox">DOMString <var>dataTransfer</var>.getData(format);
</pre>

<h3 id="Argomenti">Argomenti</h3>

<dl>
 <dt><em>formato</em></dt>
 <dd>Una {{domxref("DOMString")}} rappresentante il  tipo di dato da recuperare.</dd>
</dl>

<h3 id="Valore_restituito">Valore restituito</h3>

<dl>
 <dt>{{domxref("DOMString")}}</dt>
 <dd>Una {{domxref("DOMString")}} rappresentante i dati trascinati per il formato specificato. Se l'operazione di trascinamento non ha dati o l'operazione non ha dati per il formato specificato, questo metodo restituisce una stringa vuota.</dd>
</dl>

<h2 id="Esempio">Esempio</h2>

<p>Questo esempio mostra l'uso dell'oggetto {{domxref("DataTransfer")}} e dei metodi {{domxref("DataTransfer.getData()","getData()")}} e {{domxref("DataTransfer.setData()","setData()")}} .</p>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"&gt;
    &lt;span id="drag" draggable="true" ondragstart="drag(event)"&gt;drag me to the other box&lt;/span&gt;
&lt;/div&gt;
&lt;div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)"&gt;&lt;/div&gt;
</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css">#div1, #div2 {
    width:100px;
    height:50px;
    padding:10px;
    border:1px solid #aaaaaa;
}
</pre>

<h3 id="JavaScript">JavaScript</h3>

<pre class="brush: js">function allowDrop(allowdropevent) {
    allowdropevent.target.style.color = 'blue';
    allowdropevent.preventDefault();
}

function drag(dragevent) {
    dragevent.dataTransfer.setData("text", dragevent.target.id);
    dragevent.target.style.color = 'green';
}

function drop(dropevent) {
    dropevent.preventDefault();
    var data = dropevent.dataTransfer.getData("text");
    dropevent.target.appendChild(document.getElementById(data));
    document.getElementById("drag").style.color = 'black';
}
</pre>

<h3 id="Result">Result</h3>

<p id="EmbedLiveSample('Example'_''_''_''_'WebAPIDataTransfergetData')">{{ EmbedLiveSample('Esempio', 600, '', '', 'Web/API/DataTransfer/getData') }}</p>

<h2 id="Specifiche">Specifiche</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specifica</th>
   <th scope="col">Stato</th>
   <th scope="col">Commento</th>
  </tr>
  <tr>
   <td>{{SpecName("HTML WHATWG", "interaction.html#dom-datatransfer-getdata", "getData()")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName("HTML5.1", "editing.html#dom-datatransfer-getdata", "getData()")}}</td>
   <td>{{Spec2("HTML5.1")}}</td>
   <td>definizione iniziale</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilità_dei_browser">Compatibilità dei browser</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>4</td>
   <td>3.5</td>
   <td>{{CompatGeckoDesktop(10)}} [1]</td>
   <td>12</td>
   <td>3.1</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile(10)}}[1]</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatIE("10")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] in versioni di Firefox precedenti alla 49, questo metodo restituisce sempre una lista vuota se il tipo mime non è in una white list.</p>

<h2 id="Vedere_anche">Vedere anche</h2>

<p>{{page("/en-US/docs/Web/API/DataTransfer", "See also")}}</p>