How does Google Docs manage to get paste on click to work?

Go To StackoverFlow.com

3

I would like to implement a paste-on-click function, similar to that found in Google Docs.

I can get paste to work when initiated by the user via the context menu, or via a keyboard shortcut (using the onpaste event and friends), but I am unable to work out how to get a paste-on-click style actuation to cause the contents of the system clipboard to get pasted - and, from what I've read, this shouldn't actually be possible!

Does anybody have any clue as to how Google is making this work? :-)

2012-04-03 20:05
by mjtko


2

Did you read this article that seems to explain clipboard access with the different browsers? Google Docs and Clipboard Access

2012-04-03 20:24
by epascarello
Thanks for pointing that article out - I did read it earlier, and have reread it. When testing earlier it seemed to me that Firefox didn't work the way described (I tested under 11.0 on OSX), though now I revisit it it does work precisely the way described. I think I must have misinterpreted it slightly - I read still available in the Edit menu as the browser's edit menu, rather than the application's. So, indeed, it is impossible to paste-on-click using today's technologies - mjtko 2012-04-03 21:11


0

I know this isn't actually a solution, but more of a workaround. But maybe you'll find it worthy and would suit your needs.

Wouldn't be possible to emulate the key press for [Ctrl]+[V]? It will work on most browsers and OSes, but always keep in mind these keys can be changed at OS level anytime.

Any solution more than this kind of workaround may be too cumbersome for your script some times, and there are times when you just don't want to have too many events/listeners.

2012-04-03 20:52
by Victor Nițu
Thanks for the suggestion Victor, though this would only send Ctrl+V (or similar) to the document rather than triggering what is effectively an OS action - mjtko 2012-04-03 21:15
Look, I stumbled upon a nice article on this topic: http://brooknovak.wordpress.com/2009/07/28/accessing-the-system-clipboard-with-javascript - Victor Nițu 2012-04-03 21:52
Yes, I'm actually asking you to come back and share the results and methods if anything works out ok. I can foresee this issue as one of my own in the near future, so it would be very helpful. TIA - Victor Nițu 2012-04-03 21:54
Sorry, the click-on-paste is not possible with today's standards, though this is with caveats - it is possible in Chrome if you're willing to create an offline app (which has different sandbox rules), but I was hoping to cast the net wider than this and, in my case, an offline app is not feasible - mjtko 2012-04-04 10:36
Ads