Home Javascript JavaScript getData method
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript getData method

Advertisement
JavaScript method getData is used to get data in the specified format from the clipboard either via dataTransfer object or via the clipboardData object.

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.

 

 

 

 

 

Syntax: 

   Object.getData("DataFormat");

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 :

<html>
<script>
function copyData(){
clipboardData.setData('Text',document.selection.createRange().text);
}
function pasteData(){
txtArea.value = clipboardData.getData('Text');
}
</script>
<body>
<div style="background: #ff9900; width:'100%';" align="center">
<font color="#0000ff" size="12pt">
<b>Get Data Example</b>
</font>
</div>
<center>
</br>
<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>
</div>
<textarea id="txtArea" style="width:600; height:100; background:#ffffcc;">
Paste your text here....
</textarea>
<hr>
<button onclick="copyData();">Copy</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="pasteData();">Paste</button>
</center>
</body>
</html>

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

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 29, 2009

Related Tutorials

Ask Questions?    Discuss: JavaScript getData method   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Igie_gumiran
April 3, 2012
getdata

Thank you for your post. God Bless.
DMCA.com