3.4 C
New York
Thursday, February 2, 2023

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

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles