views:

363

answers:

2

Does anyone of you know a cross browser working way to detect paste or drag'n'drop inserts into an editable html document (with designMode or contentEditable enabled).

Detecting paste works as long as the user uses the Ctrl-V shortcut as it generated key events, but if you use the browsers Edit->Paste no events are generated it seems.

A: 

There's a paste event that works for all pastes (including via context or edit menus) in an editable document, in Firefox starting version 3.0, WebKit for a few years (not sure of version number) and IE since 5.5. Adding the paste event handler to the body element works in all these browsers.

I'm afraid I don't have any insight on drag and drop events: on the editors I've worked on I've had good reason to explicitly disable drag and drop.

Tim Down
A: 

To handle drag'n'drop you can subscribe on mouseUp event. But in this case you have to parse already pasted html.

chapluck