1constcopyText=document.querySelector("#copyMe")2constcopyMeOnClipboard=()=>{3copyText.select()4copyText.setSelectionRange(0,99999)// used for mobile phone5document.execCommand("copy")}
👋 Hey there, I am Waylon Walker
I am a Husband, Father of two beautiful children, Senior Python Developer currently working in the Data Engineering platform space. I am a continuous learner, and sha
First, be sure that you review browser compatibility that you are supporting.
Also, one thing is getting data from the clipboard and putting it on it, that is very different to implement.
I made a simple library to facilitate that work, you can check and contribute in github.com/assisfery/CopyPasteJS
cool. looking forward to giving it a try
You could also use the browser Clipboard API - "navigator.clipboard"
Yeah it's a great one. But it's still not supported by all browsers.
That's the only one to use to be honest, and according to caniuse, all browsers support it except Opera Mini and UC Browser for Android.
Just curious: What exactly are the 5 lines of code?
That's the code that does the copy.
Had no idea it was that easy 🤯. Love the addition of the code pen.
I'm glad you find value on it.
Also there is a handy, lightweight library for this
Thanks for sharing the resource
First, be sure that you review browser compatibility that you are supporting.
Also, one thing is getting data from the clipboard and putting it on it, that is very different to implement.
According to Can I Use 93.39% of browsers support this method.
And to paste something on the input field just do this
document.execCommand("paste")Cool)
👍