DEV Community

loading...

Discussion on: How to copy text to the clipboard with JavaScript (5 lines of code)?

Collapse
samydoesit profile image
samydoesit • Edited

You could also use the browser Clipboard API - "navigator.clipboard"

const str = 'String to copy'

function copyToClipboard (str) {
    navigator.clipboard.writeText(str)
}
Collapse
ibrahima92 profile image
Ibrahima Ndaw Author

Yeah it's a great one. But it's still not supported by all browsers.

Collapse
octopoulos profile image
octopoulos

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.