Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- /**
- * Copy text to clipboard
- * @param {string} text
- * @return {boolean}
- */
- const copy = (text = '') => {
- const elem = document.createElement('span');
- elem.innerText = text;
- elem.style.display = 'none';
- document.documentElement.appendChild(elem);
- const range = document.createRange();
- range.selectNode(elem);
- const sel = window.getSelection();
- sel.removeAllRanges();
- sel.addRange(range);
- const stat = document.execCommand('copy');
- document.documentElement.removeChild(elem);
- return stat;
- };
Add Comment
Please, Sign In to add comment