Jagadesh
Jagadesh

Reputation: 6807

How to read clipboard data in cross browser?

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)

Upvotes: 13

Views: 51202

Answers (2)

Tim Down
Tim Down

Reputation: 324567

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.

Upvotes: 7

V4Vendetta
V4Vendetta

Reputation: 38210

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

Upvotes: 5

Related Questions