View Full Version : Copying an image

10-05-2003, 06:05 PM
Is there a way to copy an image onto the clipboard? I tried using ExecCommand but it seems it can only copy text.

Any ideas will be appreciated.

Willy Duitt
10-05-2003, 09:57 PM
If in its own window:

alt & PrtScrn

Paste in Paint or other Image Tool

10-06-2003, 01:40 AM
But that will copy the whole screen...

10-06-2003, 04:45 PM
Sorry for my vague description. I meant is there a way to copy an image by clicking a link?

10-07-2003, 03:46 AM
I've never hear of it...

You mean that a code?
<a href="#null" onClick="CopyImage()">
Your looking for something like that? (No that won't work, lol;))

10-07-2003, 08:32 PM
Are you trying to copy the image to the clipboard so that you can move it elsewhere? If so, you can use something like this (IE-only):

//img is a reference to an <img> element
function copyImage(img) {
event.dataTransfer.setData("URL", img.src);

//sample function usage
function placeElement(container) {
var imgsrc = event.dataTransfer.getData("URL");
var newNode = document.createElement("img");
newNode.setAttribute("src", imgsrc);

Hope that helps!

Happy coding! :)