0

I want to run this javascript code when users click below anchor.. but it's not working..
is there anybody who know the problem? the code is for copyfunction. when users click anchor, copyText should be save as clipboard

 function myFunc {
    $('#link-button-1608115397633').click(function (e) {
        e.preventDefault();
        var copyText = "LASTCHANCE1";

          document.addEventListener('copy', function(e) {
             e.clipboardData.setData('text/plain', copyText);
              e.preventDefault();
         }, true);

           document.execCommand('copy');  
           alert('복사완료'); 
     })
};
judy
  • 17
  • 5

1 Answers1

1

You can insert your function in onclick of anchor instead of href.

Follow as code:

function myFunc() {
   let copyText = "LASTCHANCE1";
   
   document.addEventListener('copy', function(e) {
       e.clipboardData.setData('text/plain', copyText);
        e.preventDefault();
   }, true);
   
   document.execCommand('copy');
   alert('복사완료');      
}
<a href="#" onclick="myFunc();return false;" >Execute Func</a>