You could also use the browser Clipboard API - "navigator.clipboard"
const str = 'String to copy' function copyToClipboard (str) { navigator.clipboard.writeText(str) }
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.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.