4

There are multiple similar questions in stackoverflow which deal with how to Cut, Copy, and Paste from JavaScript (in response to a button press, for instance) without the user having to use CTRL+X, C, or V.

All these answers suggest either that you are insane for wanting to do this and that users should never have their clipboards violated in such a profane manner, or to use the hack of an invisible Flash movie (which has questionable support).

However, Google Docs does this, and does not use a Flash movie. You can open a Google Document, Go to the Edit menu, choose "Paste" (or Cut or Copy) and NOT get a browser window that tells you "Your browser security settings don't permit the editor to automatically execute copying operations."

However, go to another rich text editor (CKEditor or TinyMCE for instance, but this is common among them all) and try that same command. You will get a message that reads:

"Your browser security settings don't permit the editor to automatically execute copying operations."

So the question is simply: What is Google Docs doing to allow users to Cut, Copy, and Paste via a menu button that doesn't run in to security issues?

Community
  • 1
  • 1
CleverPatrick
  • 8,529
  • 3
  • 58
  • 81

1 Answers1

3

A quick look at all my browsers show that I have a Google Docs extension installed. I know for a fact it is possible to do with the use of an extension (Browser extensions play in a different, more "trusted" sandbox), which you could (and people do) use these to expose an API to javascript used within their sites within the browser in which the extension is installed.

Based on the fact that I definitely have extensions from google to allow "for the viewing and editing of google docs" across all my browsers - this is how they do it. Building extensions for browsers is a per-browser project and the code you write for an extension in one browser is typically only partially portable.

Google does it because its user base intrinsically trust it and so they happily download and install the necessary extensions and plugins Google publishes for varying web-based services that extend beyond the capacity of standard web technologies. We trust that Google won't get our stuff pwned.

So the short answer is: You can't do it. Unless you're prepared to write the necessary extensions/plugins for Chrome, Firefox, Safari, IE8+... etc... Google works because of an extension called Google Docs installed within your browser. (IE, in Google Chrome navigate to chrome://extensions/ to see your own google docs extension).

If you want to give extension writing a try for Chrome, visit their guide on how to do so! Be forewarned however, that installing extensions takes significant trust on a user's part and should not be required early in any "sales funnel."

Edits: Because I'm horrible at grammatically correct English

user239546
  • 456
  • 3
  • 7
  • 2
    This seems to be the answer. In FireFox I have no extensions installed from Google and I get a message that says: "These actions are unavailable via the Edit menu, but you can still use: Ctrl+C for copy Ctrl+X for cut Ctrl+V for paste" – CleverPatrick Dec 02 '14 at 14:48