0

I am creating a simple text box in my Google chrome extension popup:

<input id="textbox" type="text" size="25" style="height:30px;font-size:14pt;">
</input>

The textbox will be used to perform a search.

I have already set the focus on the textbox

document.getElementById('textbox').focus()

How can I

  • automatically copy the text on the system clipboard to the textbox, and
  • select the copied text ?
Lazer
  • 79,569
  • 109
  • 264
  • 349
  • Check out these answers: http://stackoverflow.com/questions/127040/copy-put-text-on-the-clipboard-with-firefox-safari-and-chrome http://stackoverflow.com/questions/2176861/javascript-get-clipboard-data-on-paste-event-cross-browser – dertkw May 30 '11 at 18:59
  • The first one uses a flash workaround for Firefox.. the second one is something else altogether.. – Lazer May 30 '11 at 19:03
  • While this doesn't answer the question, there are probably other extensions that do one, the other, or both. You could use those as examples. – Jared Farrish May 30 '11 at 20:45
  • I don't know if you'll find any better solutions; this would be a major security risk, no? It would allow me to build a website that surreptitiously collects everyone's clipboard data, including possible usernames and passwords – Jeff May 30 '11 at 20:56

1 Answers1

2

Sorry, it is not possible, not even with flash. Flash 9 was able to access the clipboard, but then in Flash 10 this was prohibited. Flash 10 now can only copy to clipboard, and only when you actually click it.

There used to be experimental.clipboard.* API in Chrome (or something like that), but it is gone now.

serg
  • 103,023
  • 70
  • 299
  • 324
  • Are you sure it is gone? I did not see that information [here](http://code.google.com/chrome/extensions/experimental.clipboard.html). – Lazer Jun 02 '11 at 18:37
  • @Lazer Interesting. It is gone from the developer branch docs: http://code.google.com/chrome/extensions/dev/experimental.html. Not sure is it a bug or intentional. – serg Jun 02 '11 at 19:20