Advertisement
srikat

Untitled

Apr 22nd, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. const copyToClipboard = (obj) => {
  2. event.preventDefault();
  3.  
  4. const el = document.createElement("textarea");
  5. el.value = obj.dataset.url;
  6. el.setAttribute("readonly", "");
  7. el.style.position = "absolute";
  8. el.style.left = "-9999px";
  9. document.body.appendChild(el);
  10. const selected =
  11. document.getSelection().rangeCount > 0
  12. ? document.getSelection().getRangeAt(0)
  13. : false;
  14. el.select();
  15. document.execCommand("copy");
  16.  
  17. console.log(event.target);
  18. let tooltip = event.target.querySelector("tooltiptext");
  19. console.log(tooltip);
  20. tooltip.innerHTML = "Copied: " + el.value;
  21.  
  22. document.body.removeChild(el);
  23. if (selected) {
  24. document.getSelection().removeAllRanges();
  25. document.getSelection().addRange(selected);
  26. }
  27. };
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement