Copying to clipboard

Discussion in 'Javascript' started by Butterfly Bill, Oct 29, 2009.

  1. Is it possible, using javascript, to copy the current contents of a
    text input box to the user's own computer's clipboard with a button or
    a link?

    -Bill
    Butterfly Bill, Oct 29, 2009
    #1
    1. Advertising

  2. Butterfly Bill

    VK Guest

    Butterfly Bill wrote:
    > Is it possible, using javascript, to copy the current contents of a
    > text input box to the user's own computer's clipboard with a button or
    > a link?


    Cross-browser within the default security settings: no, it is not
    possible.
    VK, Oct 29, 2009
    #2
    1. Advertising

  3. Butterfly Bill

    Evertjan. Guest

    VK wrote on 29 okt 2009 in comp.lang.javascript:

    > Butterfly Bill wrote:
    >> Is it possible, using javascript, to copy the current contents of a
    >> text input box to the user's own computer's clipboard with a button or
    >> a link?

    >
    > Cross-browser within the default security settings: no, it is not
    > possible.


    However IE still does not mind:

    <script type='text/javascript'>

    function copy(myText) {
    if (window.clipboardData) {
    window.clipboardData.setData('Text',myText);
    };
    };

    copy('Hello world!');

    </script>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Oct 29, 2009
    #3
  4. On Oct 29, 12:38 am, VK <> wrote:
    > Butterfly Bill wrote:
    > > Is it possible, using javascript, to copy the current contents of a
    > > text input box to the user's own computer's clipboard with a button or
    > > a link?

    >
    > Cross-browser within the default security settings: no, it is not
    > possible.



    Is it possible to make the document.forms.myname.value= data that
    appears in the input window appear selected (with the black box around
    it) so that the user can manually copy it?
    Butterfly Bill, Oct 29, 2009
    #4
  5. Butterfly Bill

    VK Guest

    Butterfly Bill wrote:
    > Is it possible to make the document.forms.myname.value= data that
    > appears in the input window appear selected (with the black box around
    > it) so that the user can manually copy it?


    I'm afraid I didn't understand this sentence. Do you want to make a
    page search tool like user typing in a word in a form field and the
    occurrences of this word get selected in the page content? Something
    else?
    VK, Oct 29, 2009
    #5
  6. Butterfly Bill wrote:
    > On Oct 29, 12:38 am, VK <> wrote:
    >
    >> Butterfly Bill wrote:
    >>
    >>> Is it possible, using javascript, to copy the current contents of a
    >>> text input box to the user's own computer's clipboard with a button or
    >>> a link?
    >>>

    >> Cross-browser within the default security settings: no, it is not
    >> possible.
    >>

    >
    >
    > Is it possible to make the document.forms.myname.value= data that
    > appears in the input window appear selected (with the black box around
    > it) so that the user can manually copy it?
    >


    I think you are looking for the select() function.

    document.forms.myname.select();

    --
    *****************************
    Chuck Anderson • Boulder, CO
    http://www.cycletourist.com
    Turn Off, Tune Out, Drop In
    *****************************
    Chuck Anderson, Oct 29, 2009
    #6
  7. On Oct 29, 11:47 am, VK <> wrote:
    > Butterfly Bill wrote:
    > > Is it possible to make the document.forms.myname.value= data that
    > > appears in the input window appear selected (with the black box around
    > > it) so that the user can manually copy it?

    >
    > I'm afraid I didn't understand this sentence. Do you want to make a
    > page search tool like user typing in a word in a form field and the
    > occurrences of this word get selected in the page content? Something
    > else?


    I am making a nonsense word generator and I am displaying the results
    in what is normally used as an form input text box, and I want to be
    able to copy them into Notebook or a word processor program. Yes, I
    can sweep my mouse over the box and press Ctrl+C, but I would also
    like to be able to push a button on the page to select it.
    Butterfly Bill, Oct 29, 2009
    #7
  8. On Oct 29, 1:56 pm, Butterfly Bill <>
    wrote:
    > On Oct 29, 11:47 am, VK <> wrote:
    >
    > > Butterfly Bill wrote:


    > I am making a nonsense word generator and I am displaying the results
    > in what is normally used as an form input text box, and I want to be
    > able to copy them into Notebook or a word processor program. Yes, I
    > can sweep my mouse over the box and press Ctrl+C, but I would also
    > like to be able to push a button on the page to select it.


    What worked was using:
    document.getElementById("myText").select()
    Butterfly Bill, Oct 29, 2009
    #8
  9. On Thu, 29 Oct 2009 06:20:58 +0100, Butterfly Bill
    <> wrote:

    > Is it possible, using javascript, to copy the current contents of a
    > text input box to the user's own computer's clipboard with a button or
    > a link?


    I happen to read about Zero Clipboard yesterday which uses an invisible
    Flash object to copy data: http://code.google.com/p/zeroclipboard/

    Boris
    Boris Schaeling, Oct 30, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    755
  2. Dan Bishop
    Replies:
    0
    Views:
    218
    Dan Bishop
    Aug 26, 2008
  3. Replies:
    4
    Views:
    256
    Randy Webb
    Dec 14, 2004
  4. Mahsha

    Clipboard - Copy Image To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    1
    Views:
    566
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
  5. Mahsha

    Clipboard - Copy Text To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    3
    Views:
    638
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
Loading...

Share This Page