1

Actually I want, I declare a link in javascript. And copy the link using a button.

I'm trying this. But it's showing error.

$(document).ready(function() {
      $("#copy-button").click(function() {
        var copyLink = "https://stackoverflow.com/";
        copyLink .select();
        document.execCommand('copy');
      });
    });
  body {
      padding: 20px;
    }
 <script>  src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
    <button type="button" id="copy-button" class="btn btn-lg btn-primary btn-block"> <span class="fa fa-copy"> </span> Copy </button>

I'm trying this, but not work : Copy to clipboard with Rails and Javascript via a link

نور
  • 1,425
  • 2
  • 22
  • 38
Saptam Dev
  • 495
  • 1
  • 6
  • 25
  • `document.execCommand("copy");` is the same as pressing cntrl-c with an input/dropdown/etc selected – freedomn-m Aug 20 '20 at 08:10
  • Ohh then how to do it? I want I declared the link in the javascript and copy this link. @freedomn-m – Saptam Dev Aug 20 '20 at 08:13
  • @Dev this answer has already been provided here https://stackoverflow.com/a/30810322/1886206 – ifthenelse Aug 20 '20 at 08:17
  • There are numerous existing questions, some with very detailed answers and explanations. Essentially you have to create a control, put the text in the control, copy, remove the control. Here's a detailed solution: https://stackoverflow.com/a/34192073/2181514 – freedomn-m Aug 20 '20 at 08:17
  • Hmm OK I'll follow this. – Saptam Dev Aug 20 '20 at 08:22

0 Answers0