By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,937 Members | 1,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,937 IT Pros & Developers. It's quick & easy.

Help: Copy Image to Clipboard

P: n/a
Hi,

I've searched dozens of forums and websites to find a way to have
javascript copy an image I click on into the clipboard of windows. I
found a few examples but I couldn't get any of them to work either
getting object doesnt support this method or other errors I don't
understand. If anyone has any working code for this I'd be very
thankful for it.

And yes, I know this only works in IE and I'm assuming that the user
will be using windows.

Thanks,

Kris

Sep 8 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<kr**********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,

I've searched dozens of forums and websites to find a way to have
javascript copy an image I click on into the clipboard of windows. I
found a few examples but I couldn't get any of them to work either
getting object doesnt support this method or other errors I don't
understand. If anyone has any working code for this I'd be very
thankful for it.

And yes, I know this only works in IE and I'm assuming that the user
will be using windows.


Well... just because they're using Windows doesn't mean they're using IE
(and just because they're using IE doesn't actually mean they're using
Windows). ;^)

But anyways...

I don't believe you can, via script, copy an image. The scriptable
clipboardData element in IE only supports text (and "url" which isn't
helpful to you either). It can't copy binary data.

Using the scriptable element like this:

if ( window.clipboardData ) {
window.clipboardData.setData("Text", "Text to copy.");
};

You could copy the URL to the image, the name of the image or any other
textual information you like about it - but not the actual image.

Jim Davis
Sep 8 '05 #2

P: n/a
Actually it is possible. I just found out using this code:

function CopyToClip(){
var div = document.getElementById('DivtoCopy');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';
}

Just replace DivtoCopy with the div that contains whatever you want to
copy into the clipboard.

kris

Sep 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.