Clipboard API

Jan 19, 2021
Javascript
Share on Twitter

Need to read/write to the users' Clipboard?

Write permalink


            javascript
            
          await navigator.clipboard.writeText(SOME_VALUE)

            javascript
            
          navigator.clipboard.writeText(SOME_VALUE).then(() => alert("Copied!"))

Read permalink


            javascript
            
          await navigator.clipboard.readText()

            javascript
            
          navigator.clipboard.readText().then(value => alert(`Paste ${value}!`))

  • If you need this in an iframe. Set the iframe permissions to allow clipboard read/write
  • navigator.clipboard methods return a Promise. Either await or use a callback.