OnClick image, copy text to clipboard?

by thedog
9 replies
Hi guys. I want to be able to copy text to clipboard when an image is clicked.

It's for a coupon code. I've seen this done on sites before, you click the image and it copies the coupon code to clipboard. I've also seen examples where a little bit of text displays "code copied to clipboard"

I've been searching around online and can't find anything that works...

Any ideas?

Cheers
#clipboard #copy #image #onclick #text
  • Profile picture of the author AdWordsUzmani
    I think you're looking for this ZeroClipboard v2.x
    {{ DiscussionBoard.errors[9300930].message }}
  • Profile picture of the author kdavies
    It's just a bit of javascript. You add a click event to the image, and in the click event you have the coupon code copied to the clipboard.
    {{ DiscussionBoard.errors[9300937].message }}
    • Profile picture of the author thedog
      Originally Posted by kdavies View Post

      It's just a bit of javascript. You add a click event to the image, and in the click event you have the coupon code copied to the clipboard.

      Ye... but I don't know how to do that
      {{ DiscussionBoard.errors[9300941].message }}
    • Profile picture of the author kilgore
      Originally Posted by kdavies View Post

      It's just a bit of javascript. You add a click event to the image, and in the click event you have the coupon code copied to the clipboard.
      Actually, if you want a cross-browser solution, pure JavaScript won't hack it. Most people use Flash or a third-party library (such as the one AdWordsUzmani mentioned) to get this functionality.
      {{ DiscussionBoard.errors[9301446].message }}
      • Profile picture of the author intern0t
        Is it possible for you kind sire to post source code of the page you are trying to execute this copy to clipboard on OR <img> & <coupon div> code?

        I just wanted to know how the image id and the coupon ids are interrelated in order to create a snippet.

        Thanks.
        {{ DiscussionBoard.errors[9301532].message }}
      • Profile picture of the author kdavies
        You can use a framework such as jquery or YUI. But really, what's being asked for can be done relatively easily in pure javascript and without cross browser issues.
        {{ DiscussionBoard.errors[9302561].message }}
  • Profile picture of the author smismi
    Hello thedog, if You wanna learn how javascript works You can check it out here JavaScript | Codecademy and find out everything about it and You can learn it easy.
    {{ DiscussionBoard.errors[9301646].message }}
  • Profile picture of the author David Beroff
    You may want to consider this rather elegant solution: Copy to Clipboard LMCButton

    Please let me know if you go in this direction; I actually have some enhancements which I commissioned and then gave back to the original author, but he never posted them on that site. You can have them for free.
    Signature
    Put MY voice on YOUR video: AwesomeAmericanAudio.com
    {{ DiscussionBoard.errors[9303290].message }}

Trending Topics