0

Here is my code:

function createTextArea() {
    var t = document.createElement("textArea");
    textArea = document.body.appendChild(t);

    return textArea;
}

function copy(str) {
    var textArea = createTextArea();
    textArea.value = str;
    textArea.select();
    document.execCommand("Copy");
}

copy("hello")

Now, when I try to paste, the text I placed into the textarea is not appearing. Does anyone know what I'm doing wrong?

dopatraman
  • 13,416
  • 29
  • 90
  • 154

1 Answers1

0

You have a typo according to documentatin. From Rich-Text Editing in Mozilla about executing commands

copy Copies the current selection to the clipboard. Clipboard capability must be enabled in the user.js preference file.

And see those two posts: How do you configure Firefox to allow Javascript to intercept a value pasted from the clipboard? and Copy to Clipboard for all Browsers using javascript

So, it seems very questionable if you can do that.

Community
  • 1
  • 1
Anto Jurković
  • 11,188
  • 2
  • 29
  • 42