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:
then you should set your text to the clipboard :
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.
Top comments (3)
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