Copy image to clipboard via button

Hey!

I’m trying to create a button on my website that when clicked, it copies a image to the users clipboard for them to paste elsewhere.

I’ve used the following code to copy text to clipboard so thought I’d be able to use the same but exchange the ‘text’ to ‘img’ however this didn’t work. I’ve had a look online but can’t seem to find anything explaining how to do this so am beginning to lose a bit of hope.

I’m very new to making websites and coding language so would massively appreciate it if someone could show me some example code of how this could work or if it’s impossible explain to me why.

The code I used for making the a button copy text to a clipboard (Followed by a ‘Copied’ pop up when completed) is as follows:

$w( “#text391” ).hide();
$w( “#button1” ).onClick((event) => {
let text = $w( ‘#text1’ ).text;
wixWindow.copyToClipboard(text)
.then(() => {
$w( ‘#text2’ ).show();
})
. catch ((err) => {
console.log(err)
});
});

Thankyou in advance!

Best,

Richard

The code you posted can’t be used for copying an image.

Yeah that’s the issue I’m having, do you know any code that would?

You can’t do it using Corvid. Maybe you can do it using a Custom Element.
(but I’ve never tried it. You should Google "copy image to clipboard’) or maybe there’s an npm you can install.

@jonatandor35 Ah okay, awesome though thanks for the tips will take a look! Thankyou :slight_smile: