You can access the clipboard value in JavaScript using the clipboard
API, which is available in modern browsers. The following code shows how to use the document.execCommand()
method to cut or copy a selected text into the clipboard:
index.tsx141 chars6 lines
To paste the content of the clipboard into a text field or a DIV element, you can use the document.getSelection()
and document.createRange()
methods as follows:
index.tsx395 chars15 lines
Note that the clipboard
API may not be supported in all browsers. In that case, you can use other libraries or plugins to access the clipboard value.
gistlibby LogSnag