Guest User

Untitled

a guest
Jul 15th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. 'use strict';
  2.  
  3. /**
  4. * Copy text to clipboard
  5. * @param {string} text
  6. * @return {boolean}
  7. */
  8. const copy = (text = '') => {
  9. const elem = document.createElement('span');
  10. elem.innerText = text;
  11. elem.style.display = 'none';
  12. document.documentElement.appendChild(elem);
  13. const range = document.createRange();
  14. range.selectNode(elem);
  15. const sel = window.getSelection();
  16. sel.removeAllRanges();
  17. sel.addRange(range);
  18. const stat = document.execCommand('copy');
  19. document.documentElement.removeChild(elem);
  20. return stat;
  21. };
Add Comment
Please, Sign In to add comment