Home > Article > Web Front-end > JS implements cut, copy and paste based on clipBoard.js plug-in_javascript skills
Summary:
I recently worked on a project, in which there was such a requirement: to implement a function of clicking a button to copy a link. I searched for relevant information on the Internet and found several plug-ins. ZeroClipboard is a copy function implemented through flash. As more and more people Many people proposed to abolish flash, so I wondered if copying and cutting could be achieved through js?
Address: https://github.com/baixuexiyang/clipBoard.js
Method:
Copy
var copy = new clipBoard(document.getElementById('data'), { beforeCopy: function() { }, copy: function() { return document.getElementById('data').value; }, afterCopy: function() { } });
Cut
var cut = new clipBoard(document.getElementById('data'), { beforeCut: function() { }, Cut: function() { return document.getElementById('data').value; }, afterCut: function() { } });
Paste
var paste = new clipBoard(document.getElementById('data'), { beforePaste: function() { }, paste: function() { return document.getElementById('data').value; }, afterPaste: function() { } });