Skip to content
loading...
Cover image for COPY to the clipboard in JS

COPY to the clipboard in JS

mohsenfallahnjd profile image Mohsen Fallahnejad twitter logo github logo ・1 min read

To set a textContent to the clipboard, you should get the desired element from DOM (eg. document.getElementById(“element-id”)) and access to its content:
alt text
then you should set your text to the clipboard :
alt text
and when this function is executed, it’s done…!

If you found it useful, you can follow me and also visit my website, because there are more ways to connect with me. I hope this would help you to improve your coding skills. Thank you for your attention.


This article was originally published on The Dev.to on April 8, 2020 and was written by Mohsen Fallahnejad.

twitter logo DISCUSS (4)
Discussion
markdown guide
 

It's probably still a good idea to use the temporary textarea hack described here:

stackoverflow.com/a/46822033/5323344

window.navigator.clipboard is not yet supported in Microsoft Edge. It is supported in Firefox and Chrome, though.

 

When you thought dropping IE was enough. Edge still falls short in a bunch of aspects for dev :(

 
 

that's true
I have seen this way
And I just wrote the solution that I worked with
But in any case, what you said is true
Thank you for your attention and reminding

Classic DEV Post from Aug 1 '19

Which dev.to loading GIF do you prefer?

I made some dev.to loading gifs

Mohsen Fallahnejad profile image
I like JavaScript codding in Front-end form and especially Vue.js