Explore Clipboard Operation in JavaScript | by Sabesan Sathananthan | Geek Culture

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('copy') — copy
  • Document.execCommand('cut') — cut
  • Document.execCommand('paste') — paste

Copy or Cut operation

Paste operation


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

Clipboard object

  • 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

Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: