2

iam traing to make a tampermonkey script auto paste some text in text box but iam confusied after many ways iam still not able to make it, i already try document.execCommand("Paste") but nothing document.execCommand("Paste") doesn't work! "Copy" and "cut" works fine.

document.getElementById("email").execCommand('Paste');
timomo
  • 67
  • 1
  • 8
  • 1
    This is not how execCommand is used. First you need to focus the element e.g. `document.getElementById("email").focus()` then call `document.execCommand()`. However, the `paste` command won't work at all because it requires a special security permission which Tampermonkey doesn't provide: `clipboardRead`. No userscript extension provides that AFAIK. You can use the new asynchronous Clipboard API instead, look for examples. – wOxxOm Jun 22 '20 at 04:39
  • You could instead insert the text by setting the innerText/innerHTML. – CennoxX Jun 25 '20 at 08:15
  • [`Clipboard`](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) on MDN. – double-beep Nov 28 '21 at 12:33
  • Does this answer your question? [Get current clipboard content?](https://stackoverflow.com/questions/6413036/get-current-clipboard-content) – double-beep Nov 28 '21 at 12:43

0 Answers0