Results 1 to 3 of 3

Thread: To copy-paste using Javascript.

  1. #1
    Join Date
    Feb 2009
    Posts
    55

    To copy-paste using Javascript.

    hello friends,

    I wanna know how can I perform copy-paste operations using javascript.
    Does anyone have the script for this ? ........ kindly post

    thanks a lot...

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: To copy-paste using Javascript.

    Sometimes, when the user submits a form you may want to offer him the possibility to copy the content of a field (such as a textarea) to the clipboard so that if something goes wrong he doesn't lose what he just wrote.
    Here is the JavaScript code to COPY :

    Code:
    <script type="text/javascript">
    function CopyToClipboard()
    {
       CopiedTxt = document.selection.createRange();
       CopiedTxt.execCommand("Copy");
    }
    </script>
    In HTML you need to make this work like this:

    Code:
    <form name="Form1">
    
    Here is some text you can copy. You can copy text from anywhere on the page, simply select it and press the Copy to clipboard button. Then you can paste it anywhere you want, in Notepad, Visual Studio or in the textarea below.
    
    <br /><br />
    
    <textarea id="txtArea" cols="60" rows="5">You can also copy text from this textarea. Or you can paste the text here, using the Ctrl+V key combination.</textarea>
    
    <br />
    
    <input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" />
    
    </form>

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: To copy-paste using Javascript.

    To COPY-PASTE:
    Here's the JavaScript you need to use for implementing both a copy button and a paste button:

    Code:
    <script type="text/javascript">
    function CopyToClipboard()
    {
       CopiedTxt = document.selection.createRange();
       CopiedTxt.execCommand("Copy");
    }
    function PasteFromClipboard()
    {  
       document.Form1.txtArea.focus();
       PastedText = document.Form1.txtArea.createTextRange();
       PastedText.execCommand("Paste");
    } 
    </script>
    In HTML, you need to make this work like this -

    Code:
    <form name="Form1">
    Select this text, copy it using the copy button, and paste it below.<br /><br />
    <textarea id="txtArea" cols="60" rows="5"></textarea>
    <br />
    <input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" />
    <input type="button" onClick="PasteFromClipboard()" value="Paste from clipboard" /> 
    </form>

Similar Threads

  1. Replies: 5
    Last Post: 26-04-2012, 04:16 AM
  2. copy& paste in facebook
    By ramada90 in forum Technology & Internet
    Replies: 2
    Last Post: 24-07-2011, 10:59 PM
  3. Copy and paste a conditional
    By Halina in forum Software Development
    Replies: 5
    Last Post: 16-04-2009, 11:59 PM
  4. Replies: 0
    Last Post: 18-03-2009, 10:00 PM
  5. Copy and Paste does not work
    By M.Scarlet in forum Microsoft Project
    Replies: 1
    Last Post: 06-02-2008, 03:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,717,666.19045 seconds with 17 queries