0

Here, I am not able to copy the data from clipboard in Mozilla Firefox.

{
  var cTxt = "abc"; // here it is dynamic data - i have given abc as static here
  var contInp = document.createElement("input");
  contInp.setAttribute("value", cTxt);
  document.body.appendChild(contInp);
  contInp.focus();
  contInp.select();
  document.execCommand("copy");
  document.body.removeChild(contInp);
}

Can anyone please help me sort out this problem? It is working fine in Chrome.

lloydaf
  • 605
  • 3
  • 17
  • 1
    I don't know how are you calling the code, but possible duplicate of [javascript - Cannot use `document.execCommand('copy');` from developer console - Stack Overflow](https://stackoverflow.com/questions/33321095/cannot-use-document-execcommandcopy-from-developer-console) if the reason is the same. – user202729 Dec 04 '18 at 10:24
  • Possible duplicate of [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – Ratan Uday Kumar Dec 04 '18 at 10:24
  • Your code [works just fine](https://codepen.io/anon/pen/zMXJmY?editors=1010). You're possibly not binding it to a user initiated event and the browser aborts it. – Álvaro González Dec 04 '18 at 10:31

0 Answers0