Home > Code > Javascript > Copy to clipboard using JavaScript

Copy to clipboard using JavaScript

by Shiva murugan   on May 22, 2011   Category: Javascript   |  Views: 4203    |  Points: 25   |  Bronze 

Sometime we may have scenario like copy small/huge data from application to other places, so in this situation JavaScript - window.clipboardData.setData used to copy the required details from div or other controls in the application see the below JavaScript function.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication2.WebForm3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Copy to ClipBoard Test</title>

<script language="javascript" type="text/javascript">
function CopyToClipboard(clipdata) {
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);

<form id="form1" runat="server">
<div id="text" runat="server">
Copy to clipboard test..
<a href="#" id="copytext" onclick="javascript:CopyToClipboard(document.getElementById('text').innerHTML);">
Click here copy to clipboard</a>
<br />
<br />
<asp:TextBox ID="TextBox1" TextMode="MultiLine" runat="server" Height="88px" Width="312px">Paste here.</asp:TextBox>

Note: Above code works only IE browser.

Post Code  |  Code Snippet Home

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts