A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/DataTransfer/getData below:

getData ยท WebPlatform Docs

getData Summary

Gets the data in the specified format from the clipboard through the DataTransfer object or the ClipboardData object. If there is no data, returns an empty string.

Method of dom/DataTransferdom/DataTransfer

Syntax
var eventData = event.dataTransfer.getData(format);
Parameters format
Data-type
String

The format of the data to be transferred, using one of the following values (case insensitve):

Return Value

Returns an object of type StringString

Returns the data in the format retrieved from the clipboard/drag and drop operation through the DataTransfer object or the ClipboardData object. Depending on the information contained in setData, this variable can get a path to an image, text, or an anchor URL.

Examples

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

<!doctype html>
<html>
 <head>
  <script>
var sImageURL, oTarget, oImage;
function initiateDrag(e) {

  e.dataTransfer.setData("URL", oImage.src);
}
function finishDrag(e) {

  sImageURL = e.dataTransfer.getData("URL");
  oTarget.textContent = sImageURL;
}
function initialize() {
 oImage = document.getElementById("oImage");
 oTarget = document.getElementbyId("oTarget");
 oImage.addEventListener("dragstart", initiateDrag, false);
 oTarget.addEventListener("dragenter", finishDrag, false);
}
window.addEventListener("load", initialize, false);
  </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>
  <img id="oImage" src="/workshop/graphics/black.png" width="20" height="20" alt="Black">
  <span id="oTarget">
    Drop the image here
  </span>
 </body>
</html>

View live example

Notes Related specifications
HTML5
Candidate Recommendation
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4