Advertisement
cloudtuts

JS Copy Text

May 12th, 2022
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CopyURL(){
  2.     let copy = document.createElement('textarea'),
  3.             top = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0),
  4.             result;
  5.  
  6.     document.body.appendChild(copy);
  7.     copy.value = $(this).data('url');
  8.     copy.focus();
  9.     copy.select();
  10.  
  11.     try {
  12.         result = document.execCommand('copy');
  13.     } catch (error) {
  14.    
  15.     }
  16.  
  17.     document.body.removeChild(copy);
  18.     alert('已複製網址 ' + $(this).data('url'));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement