2 May, 2022
clipboard is short-term storage to keep some information and data for some moment. The operating system provides this storage for applications to keep relevant data for a shorter duration such that the application/program can read it at a later point in time. The clipboard's content is usually managed in the computer's RAM(Random Access Memory).
navigator object has the helpful
clipboard API methods. The `writeText()' method is responsible for copying(or writing) to the clipboard.
writeText() method takes the value to copy(or write to the clipboard) as an argument. You must also handle the error using a try-catch block. The code snippet above shows how to copy to the clipboard using the writeText method.
readText() is used to read the content from the clipboard,, and thus, you can paste it to a target application.
Several web browsers already support the
clipboard APIs. You can check the current support from here. As a measure, you must check for the
navigator.clipboard availability using a simple
if-else condition as we have seen in the code snippets above.
Also, check the extensive API documentation from the MDN Doc.
That's all for now. I hope you found this article helpful.
Let's connect, I keep sharing tips & knowledge on these platforms: