How to simulate a CTRL + V with javascript

Asked

Viewed 697 times

1

I would like to paste a text from the clipboard using javascript, is not an extension is a web page.

I tested the command document.execCommand('Paste') in some ways didn’t work out, I’m using Google Chrome.

  • I really don’t understand how browsers are allowing access to things as surreal and insecure as knowing what the user has in the memory of the Clipboard. This is going to be serious trouble.

  • The duplicate answers yes to the question. Excerpt from one of the answers: Basically, you can’t access clipboard content on most browsers. Because, obviously, this is considered a security problem

2 answers

2

  • A common need for Extensions is to have a single long-running script to Manage some task or state. Background pages to the Rescue. I think this has more to do with Chrome extensions than with web pages

  • yes, this type of command is authorized only by the.

  • You’re right, I hadn’t seen that in your reply. Reading error =)

  • 1

    I just added this part "which are extension pages." to make it clearer.

0

The command document.execCommand('paste') has never been a stable Javascript command. It was a temporary solution created to help developers program in the version Chrome Dev and is apparently part of the API for Chrome extensions.

She was removed from Firefox for security reasons and apparently only the commands Cut and Copy work in Chrome, even to work it is necessary that the user has selected a part of the page text. The command Paste always returns false because it is never possible to execute it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.