0

I tried to access the clipboard but Chrome and Firefox only interpret undefined. How can I improve the code?

JavaScript:

function handlePaste(e) {
for (var i = 0 ; i < e.clipboardData.items.length ; i++) {
var item = e.clipboardData.items[i];
console.log(item );

source of that code

daisy
  • 615
  • 2
  • 8
  • 15
  • This seems like it's not a standard API yet. Each browser has its own way of doing it. It works fine in Chrome 34 and Firefox 24 if you do it the way the browser wants: http://jsfiddle.net/42jLC/ – gen_Eric Apr 15 '14 at 19:15
  • That can be a hassle to implement, I'd look at this it's very helpful : http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript?rq=1 – xd6_ Apr 15 '14 at 19:16
  • I think at this point your best bet is to use flash, but remember that won't work on iOS. – Jeffpowrs Apr 15 '14 at 19:25

1 Answers1

1

I am afraid there is no easy way, since browsers disable this kind of behaviour. Even google docs asks you to use your keyboard shortcuts to copy and paste.

There is a library that uses flash to achive what you want, but again, not 100% reliable.

http://www.steamdev.com/zclip/

Timur
  • 639
  • 6
  • 21
  • keyboard shortcuts to copy and paste, that is what I would like to have, is google using flash? – daisy Apr 15 '14 at 20:45
  • @daisy i meant that even google docs cant access your clipboard. They tell you to copy and paste text using your keyboard. – Timur Apr 16 '14 at 14:25