Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. const copyToClipboard = str => {
  2. const el = document.createElement('textarea');
  3. el.value = str;
  4. el.setAttribute('readonly', '');
  5. el.style.position = 'absolute';
  6. el.style.left = '-9999px';
  7. document.body.appendChild(el);
  8.  
  9. const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
  10.  
  11. el.select();
  12. document.execCommand('copy');
  13. document.body.removeChild(el);
  14.  
  15. if (selected) {
  16. document.getSelection().removeAllRanges();
  17. document.getSelection().addRange(selected);
  18. }
  19. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement