Geek Culture
Published in

Geek Culture

Explore Clipboard Operation in JavaScript

Cut, Copy and Paste in JavaScript

Photo by Alex Green from Pexels
  • Document.execCommand()method
  • Asynchronous Clipboard API
  • copy,cut and paste Events

Document.execCommand() method

  • Document.execCommand('copy') — copy
  • Document.execCommand('cut') — cut
  • Document.execCommand('paste') — paste

Copy or Cut operation

Paste operation

Disadvantage

Asynchronous Clipboard API

const clipboardObj = navigator.clipboard;
The permission prompt for the Clipboard API.

Clipboard object

Copy, Cut, and Paste Events

  • Event.clipboardData.setData(type, data) : To modify the clipboard data, you need to specify the data type.
  • Event.clipboardData.getData(type) : To obtain clipboard data, you need to specify the data type.
  • Event.clipboardData.clearData([type]) : Clear clipboard data, you can specify the data type. If you do not specify the type, all types of data will be cleared.
  • Event.clipboardData.items : An array-like object contains all clip items, but usually there is only one clip item

Conclusion

--

--

A new tech publication by Start it up (https://medium.com/swlh).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sabesan Sathananthan

Software Engineer 👨‍💻 @SyscoLABSSL | Postgard🧑‍🎓 in CSE at UOM | Technical Writer ✍️ | sabesansathananthan.now.sh | Still makes silly mistakes daily.