Skip to main content

Copy to clipboard in javascript with zeroclipboard flash for all browser.

This article describe you how to copy text from webpage in button click using javascript or using flash that works on all major browser.

Check out these excellent article too how to select all div text in single click in JavaScripthow to highlighting text inside div in JavaScriptFinding, convert text input into hyperlink in JavaScript

below is three code sample two of them works only on Internet Explorer (Prompt may be display as per your browser security policy i.e. allow website to access your clipboard.)  and another one works in all major browser that using flash for copy to clipboard functionality.

Flash is the only way to make copy to clipboard functionality that works in all major browser because for security reason browser excluding IE can not access clipboard through javascript.

Copy To Clipboard In JavaScript Using clipboardData class (Works only on IE).

function copyToClipboard() {
     var copyText = document.getElementById('pDesc').innerText;
     window.clipboardData.setData("Text", copyText);
     alert('Copy To Clipboard : \n'+ copyText);

HTML Part :
<a id="copy-button" onclick="copyToClipboard()"Copy To ClipBoard </a>
<p id="pDesc">
    this article explains how to copy text from the page that works only on Internet Explorer.

Copy To Clipboard In JavaScript Using execCommand (Works only on IE).

function copyToClipboard() {
    var copyText = document.getElementById('txtCopyText');
    if (!document.all) return; // IE only
    copyTextRange = copyText.createTextRange();
    alert('Copy To Clipboard : \n'+ copyText.value);

HTML Part :

<input type="text" id="txtCopyText" value="hello" />

<input type="button" id="btnCopy" onclick="copyToClipboard()" value="Copy To ClipBoard" />

Below is the code that is using zeroclipboard.swf for coping the text that can be download from given link below.
Copy To Clipboard With Flash (All Major Browser).

<script type="text/javascript" src="Scripts/jquery.js"></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(document).ready(function () {
        path: "",
        copy: function(){return $('#txtCopyText').val();},
        beforeCopy: function () { },
        afterCopy: function () {
            alert('Copy To Clipboard : \n'$('#txtCopyText').val());

HTML Part :
<a id="copy-button" Copy To ClipBoard </a>
<input type="text" id="txtCopyText" value="" />

Copy To ClipBoard With Flash (Reference ) :

Check Demo Here :
  Copy To ClipBoard

Copy to clipboard in javascript and zeroclipboard flash 10 for all browser.

Popular posts from this blog

how $document.ready() is different from window.onload()

we often use window.onload() in javascript and $document.ready() in jquery and assume that both are same just jquery library wrap up javascript window.onload() and introduce $document.ready() but no there is much difference between them below is the explanation -

regex - check if a string contains only alphabets c#

How to validate that input string contains only alphabets, validating that textbox contains only alphabets (letter), so here is some of the ways for doing such task. char have a property named isLetter which is for checking if character is a letter or not, or you can check by the regular expression  or you can validate your textbox through regular expression validator in Following code demonstrating the various ways of implementation.

Merging multiple PDFs using iTextSharp in c#

In this article i will show you how to merge multiple pdfs into one using ITextSharp below is the two approach one is to pass your input files path, output file path (will be created if not exist) and another is pass direct input stream, output stream and it will write the merge files into output stream.

How to handle click event of linkbutton inside gridview

Recently I have posted how to sort only current page of gridview , Scrollble gridview with fixed header through javascript , File upload control inside gridview during postback and now i am going to explain how to handle click event of linkbutton or any button type control inside gridview. We can handle click event of any button type control inside gridview by two way first is through event bubbling and second one is directly (in this type of event handling we need to access current girdviewrow container)