admin管理员组

文章数量:1345324

I am building a web page and have run into something that would be nice to be able to do; set text to be copied to the clipboard when someone tries to copy an image, probably the same as the alt text. Is there any way with javascript/html that this can be done? If so, please explain.

Thanks for any help!

Edit: Basically, I want to let my users highlight the image, press control-c, and then have the alt text stored in their clipboard.

I am building a web page and have run into something that would be nice to be able to do; set text to be copied to the clipboard when someone tries to copy an image, probably the same as the alt text. Is there any way with javascript/html that this can be done? If so, please explain.

Thanks for any help!

Edit: Basically, I want to let my users highlight the image, press control-c, and then have the alt text stored in their clipboard.

Share Improve this question edited Jul 28, 2012 at 3:00 asked Jul 28, 2012 at 2:54 user1559041user1559041 6
  • Are you looking to just copy the alt text? Or HTML that contains the image and some sort of caption with it? – Brad Commented Jul 28, 2012 at 2:56
  • Just to copy the alt text when someone highlights the image and copies it would be great. – user1559041 Commented Jul 28, 2012 at 2:58
  • Normally no images get copied on pressing cttl + c when hovered on a image. So what you means by highlighted? – McLosys Creative Commented Jul 28, 2012 at 3:20
  • I think only IE supports oncopy for images and you'd probably need flash for the copying to clipboard part – Musa Commented Jul 28, 2012 at 3:25
  • @McLosysCreative Hightlight as in clicking down and dragging over it, the way you would copy text. – user1559041 Commented Jul 28, 2012 at 12:26
 |  Show 1 more ment

4 Answers 4

Reset to default 5

add attribute alt="text" to your image

example:

<img alt="

本文标签: javascriptHow can I set text to be copied to clipboard when image is copiedStack Overflow