How to read clipboard data in cross browser?

Jagadesh picture Jagadesh · Apr 5, 2011 · Viewed 49.1k times · Source

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)

Answer

Tim Down picture Tim Down · Apr 5, 2011

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.