35 Comments to “Onclick Select All and Copy to Clipboard (javascript)”

  1. Brad

    Apr 19th, 2008

    Well this is just terrible. Just use this simple bit of code in the textbox or textarea.

    onFocus=”this.select();”

    Or maybe I’m just misinterpreting what your trying to do.

  2. Sajith M.R

    Apr 19th, 2008

    Brad,
    Here not only just select, also copy the content into your clipboard.

    (Similar to right click select all and copy)

  3. tonk

    Apr 19th, 2008

    goosebumps

  4. Derive Host

    May 5th, 2008

    Great Post.

    Best Regards
    Team
    Web Hosting Sri Lanka

  5. Pigeon

    May 6th, 2008

    It doesn’t work, at least not in Opera, the line

    r.execCommand(\’copy\’);

    gives an inline script compilation error at the escaped quotes. If I unescape the quotes it gives a type mismatch error on the same line.

  6. topigeon

    Jun 2nd, 2008

    What part of “The html part is:

    The above script will select all the text for input field and copy to clipboard (for IE only)” do you not understand? IE = Internet Explorer != Opera.

  7. selva

    Jul 18th, 2008

    how to copy a text in textbox to clipboard in mozilla???

  8. Lindsay-Lohan

    Jul 31st, 2008

    thanks! very nice!

  9. Anna8

    Aug 4th, 2008

    Yes, great job. :) Interesting indeed.

  10. Raja

    Aug 28th, 2008

    Check this link… working good…
    Copy to Clipboard

  11. Neenbyday

    Oct 2nd, 2008

    How i may contact admin this site? I have a question.
    iijiivei

  12. Sajith M.R

    Oct 2nd, 2008

    You can mail me at: admin@sajithmr.com

  13. MegranFuyis

    Oct 3rd, 2008

    i newbie plz how us the baton “add me”?

  14. Narosponura

    Oct 27th, 2008

    All greetings! I have fallen in love today:)))))
    I wish to shout about love to all world ! :)
    Love this magnificent feeling:)))))

  15. Nick

    Nov 6th, 2008

    Nice one, this is really handy – thanks very much indeed. I prefer the this.select(); route myself as it’s so simple..

    Does anyone know an equally simple way to copy the contents to clipboard (in any browser)?

    Thanks very much indeed.

  16. Sexualxe

    Nov 7th, 2008

    Hello you forum best. And Bye. just test. . :) :) :) :) :) :) :) :) :) :) :) :)

  17. sairiurse

    Nov 15th, 2008

    to: Admin – If You want to delete your site from my spam list, please sent url of your domain to my emai: stop.spam.today@gmail.com
    And I will remove your site from my base within 24 hours
    webmastegz

  18. HSCharles

    Nov 16th, 2008

    I have a flash site
    i’m looking for the script who shows google ads with flash.
    how can i get it?

  19. a

    Dec 9th, 2008


    is there a way to do select all with for example ?

  20. iTashaLIL

    Dec 10th, 2008

    Hellow

    Could you help me. I have troubles with your site. It it works not fast.
    Can somebody help me to solve the problem or explain why it can be so?

    Thanks

  21. QuicMicaPrurb

    Dec 28th, 2008

    Hi, just saying a blated hello ;)

  22. Job Abijah

    Dec 30th, 2008

    This is very handy indeed – thank you very much for posting.

    @Pidgeon – I just tested it in opera and it worked fine for me (in addition to IE, Safari & Firefox)

    Anyway thanks very much for posting this, very useful cheers.

  23. ertarunz7

    Jan 17th, 2009

    Hii … Thanks for the script … But sorry its not working for me … can any one place an example for this .

    Thanks

  24. ertarunz7@gmail.com

    Jan 17th, 2009

    I have found one more similar scripts and it worked fine for me so i thought posting it here .. so that it may help you all.. but its working only in IE.
    Please see if any one get one that works for all (firefox, IE … )

    function ClipBoard()
    {
    //holdtext.innerText = copytext.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand(”RemoveFormat”);
    Copied.execCommand(”Copy”);
    }

    // Html part

    hello all

    Copy to Clipboard

    Thanks

  25. ertarunz7@gmail.com

    Jan 17th, 2009

    Re-writting HTML part .. please remove quotes ..

    <!– hello all

    Copy to Clipboard –>

  26. hireecdorrozy

    Jan 22nd, 2009

    Using internet is simple as hell. But I can tell y ou right now, it can be very hard, if you are the first time user.
    So, first thing I suggest – open the Explorer, and type in the address you like.
    You’ll get there really fast, it depends on your connection speed.
    Good luck.

  27. AlexStivenson

    Feb 15th, 2009

    How you think, in our situation whis crisis its actual?

  28. Sandro

    Feb 23rd, 2009

    I have great difficulty understanding why some programming experts waste time by displaying outdated scripts that only function in IE.
    The whole purpose of the WWW is to produce platform, and browser independent code that everyone can use.
    I can recommend the w3c org where much discussion centres around ONE single standard.

  29. brian

    May 5th, 2009

    i’ve been looking for this all over, thanks for the great post.

  30. prafuldass

    May 23rd, 2009

    thanks for the post

  31. daya

    May 28th, 2009

    great soluation.
    thanks

    Well this is just terrible. Just use this simple bit of code in the textbox or textarea.
    onFocus=”this.select();”
    Or maybe I’m just misinterpreting what your trying to do.

  32. kraloyun

    Jun 16th, 2009

    Is there any other code shorter than this – A one line text which will select & copy the clicked area ?

  33. Greg Landers

    Aug 4th, 2009

    Add this to a textarea or text input so that when click anywhere on the field, it automatically selects all and copy’s to the clipboard.

    onclick=”this.select(); var r= this.createTextRange(); r.execCommand(’copy’);”

  34. slashlu

    Nov 13th, 2009

    thanks for your code,it’s help for me

  35. feclaisee

    Dec 18th, 2009

    Hi.
    My PC worked not correctly, too much errors. Please, help me to fix errors on my PC.
    My operation system is Win Vista.
    Thanks,
    feclaisee


Leave a Reply