Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy javascript made images to clipboard

Is there today with HTML5 a way to copy to clipboard, without browser plugins (and so without Flash nor java) nor short-term hacks, an image built in a canvas ?

The copy to clipboard would be initiated by javascript but having user confirmation or a dialog isn't a problem.

Solutions which don't work in Windows and Linux, or which don't work at least in Chrome and Firefox are without interest to me.

Ideally I would prefer a solution that doesn't impose to display the image (which is built in memory with document.createElement('canvas')) but that's not an absolute requirement.

like image 259
Denys Séguret Avatar asked May 15 '12 07:05

Denys Séguret


People also ask

How do you copy an image to clipboard?

Go to the Images folder and look for the image you want to copy. Long press the image. Tap on the copy icon at the bottom left. Your image is now copied to the clipboard.

Can you copy and paste JavaScript?

JavaScript offers some built-in clipboard properties that allow us to copy/paste the text into the clipboard using a single button click. In JavaScript, the navigator. clipboard is used to get access to the clipboard while writeText() property is used to copy the text into the clipboard.

How do I use JavaScript clipboard?

select() to select the contents of the <textarea> element. Use Document. execCommand('copy') to copy the contents of the <textarea> to the clipboard. Remove the <textarea> element from the document.


1 Answers

As far as I'm aware, the Clipboard API is the only specification in this area. I've never used it and don't know how widely it's supported, but I suspect not widely. According to this quick and dirty test, the current versions of Chrome and Firefox fire the copy event. I believe the user has to initiate the copy (e.g., you say "press Ctrl+C to copy").

IE makes window.clipboardData available, but as far as I know you're limited to text and URLs.

So sadly, I think this is one of those answers that's basically: No, not yet.

like image 101
T.J. Crowder Avatar answered Sep 19 '22 00:09

T.J. Crowder