13

Possible Duplicates:
Copy / Put text on the clipboard with FireFox, Safari and Chrome
How to Copy to Clipboard in JavaScript?

Hi ,

scenario: I copied some content (either from notepad or word) and want to paste it in my iframe. On before pasting i want to manipulate the clipboard content. In IE i can do it with window.clipboardData.getData("Text"); How to read the clipboard data in other browsers (FF/chrome and safari)

Community
  • 1
  • 1
Jagadesh
  • 5,841
  • 6
  • 24
  • 30
  • 6
    @David, @Crowder: Both those questions are undoubtedly similar to this one but both concern putting data onto the clipboard rather than reading data from it. – Tim Down Apr 05 '11 at 13:05
  • @David, @Crowder: It is a possible duplicate of this question though: http://stackoverflow.com/questions/233719/is-it-possible-to-read-the-clipboard-in-firefox-safari-and-chrome-using-javascri – Tim Down Apr 05 '11 at 13:13
  • 2
    Jesus christ SO needs to moderate the mods so badly. Neither of the questions this was marked as a dupe of are the same question at ALL. – B T Jun 27 '16 at 09:05

2 Answers2

7

You'll only be able to do this in most browsers when the user explicitly triggers a paste (for example, by using Ctrl-V or the edit or context menus).

In Firefox and Opera you'll need to use a hack, such as the one I outlined here: JavaScript get clipboard data on paste event (Cross browser).

In Internet Explorer, Safari and Chrome, you can access the clipboard directly during a paste using window.clipboardData in IE and the paste event's clipboardData property in WebKit. More information can be found on the Apple developer site.

Community
  • 1
  • 1
Tim Down
  • 292,637
  • 67
  • 429
  • 506
5

Incase of Firefox

By default, JavaScript is not allowed to read or set your clipboard data for security and privacy reasons. This is because websites scripts can erase and replace what you currently have in your clipboard (data loss issue) and they can read whatever you have in your clipboard (security and privacy issue)

From Here

V4Vendetta
  • 34,000
  • 7
  • 73
  • 81
  • nowadays Document.execCommand('paste') [read there](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) – Dima Fomin Feb 17 '17 at 13:52