[an error occurred while processing this directive]

JavaScript getData method


JavaScript method getData is used to get data in the specified format from the clipboard either via dataTransfer object or via the clipboardData object. It returns the data in the format retrieved from the clipboard through the dataTransfer object or the clipboardData object which is totally based on the setData.








Where "DataFormat" may be either "Text" or "URL". If it is "Text" then it gets the data formatted as text and if it is "URL" then it gets the data formatted as a URL.

Description of code:

In our example code we have created two functions for copying data and pasting data to the described text area. These two functions copyData() and pasteData() is called when user clicks on the buttons Copy and Paste. Before copying data we need to select the data otherwise in the clipboardData object "null" value would be set and it will be further pasted to the text area. Here is the following html example code for getDataExample method as follows :

function copyData(){
function pasteData(){
txtArea.value = clipboardData.getData('Text');
<div style="background: #ff9900; width:'100%';" align="center">
<font color="#0000ff" size="12pt">
<b>Get Data Example</b>
<div style="background: #0099ff; width:'100%';" align="center">
<p>Rose India Technologies Pvt. Ltd. is a global services company that ensures maximum returns by providing quality software solutions and services. The Indian based company provides services to several reputed institutional clients, in the domain of IT and IT enabled Technologies. We help in understanding the client requirements and offer customized solutions in various specialized areas like Web based Technologies, Database Systems, Client Server Architecture, E-commerce Solutions and Consultancy Services</p>
<textarea id="txtArea" style="width:600; height:100; background:#ffffcc;">
Paste your text here....
<button onclick="copyData();">Copy</button>
<button onclick="pasteData();">Paste</button>

Output :

Select the data to which you want to copy.

Click on the Copy button to get data which is selected by you and now click on the Paste button to paste the copied text data to the text area.

You can also download the full source code from the provided link as given below.

Download Source Code


[an error occurred while processing this directive]