Javascript Copy Text To Clipboard

Issues arise when you want to copy text to the clipboard using javascript. Firefox provides a security measure which prevents you from doing it so a workaround has to be made for it to happen. I am using IE7 for my IE testing and in this version, it also has a security feature although less strict than Firefox. Whenever you browse to a new page that has a copy to clipboard function, a popup window prompts you asking if you want to allow the webpage to access your clipboard. Normally, you would choose no. But instances may require you to like if the site you are accessing is yours or related to your needs and you have the utmost trust that the script won’t harm your PC or something. Anyway, to provide copy to clipboard functionality using Javascript, I found this function in this site does the job by using a little .SWF file. You can download the file there or if you want to use Google App Engine, the code function below will do. It also works in Safari, IE, and Opera.

Related Posts Plugin for WordPress, Blogger...
  1. 14 Responses to “Javascript Copy Text To Clipboard”

  2. once I had questions about web coding, I know where to go.. Here on your website.. Thanks for the info.

    Beyond The Rave Reality
    Personal Blog Money
    Seek Health. Feel Great

    By anneberly on Aug 28, 2008

  3. i want to learn java next time

    By treen on Aug 28, 2008

  4. another interesting post for programmers.. Thanks for the info…

    Seek Health. Feel Great
    Personal Blog Money
    Beyond The Rave Reality

    By anneberly on Aug 30, 2008

  5. Thank’s for this code.
    I think this code doesn’t work on vista. DO you have a workaround?

    kind regards, Daniel

    By Daniel on Oct 28, 2008

  6. hi daniel, it’s not the os that’s the problem, it’s the browser. which browser are you using and what version? i tried this with ie7 and it was ok. i usually use firefox.

    By tech on Oct 28, 2008

  7. I’ve found recently that this little trick stopped working in Firefox. I am not sure yet if they have closed this “hole” in the recent releases or what the problem is. IE7 still works (w/ a one-time warning), but FF doesn’t.

    By Brian on Oct 30, 2008

  8. Doesn’t work for me.. I’m on Safari 3.1.2/Flash 9.. Too bad.. I’m desperately looking for a solution to this..

    By Benjamin A. Wendelboe on Oct 30, 2008

  9. this is odd, because in firefox 2 and 3, this works. i checked it again. perhaps you installed a flash swf blocker plugin? because that won’t work unless you start the flash plugin used to copy the text to clipboard.

    i also checked this out in safari 3.1 (525.13). would be weird if a new version can’t support old ones.

    IE6 works fine. i checked it again :)

    By tech on Oct 30, 2008

  10. This method is not working if you install Flash 10 due to some security changes.

    http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html#head31

    Looking for a workaround :)

    By Bill Beckelman on Nov 30, 2008

  11. This is a very important post, I was looking for this information. Just so you know I found your blog when I was browsing for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.

    By Young Matros on Apr 10, 2010

  12. Yes but that true

    By Forum informatique on Jul 20, 2011

  1. 3 Trackback(s)

  2. Aug 28, 2008: Javascript Copy Text To Clipboard : Dtv 2009
  3. Aug 28, 2008: Javascript Copy Text To Clipboard : insuranceslowprices
  4. Oct 13, 2008: Javascript: Copy Text to Clipboard « My Weblog

Post a Comment