Andrew
Andrew

Reputation: 2851

Copy + Paste events not working in jQuery / Firefox

I have an app where users can copy and paste elements. I use the built-in events "copy" and "paste". Here's an example:

$(document).on('copy',myCopyFunction).on('paste',myPasteFunction);

This works great in Chrome. However, in Firefox, it doesn't work at all. Here's a fiddle to demonstrate (note you need to click the window the script is running in to listen for keyboard events):

http://jsfiddle.net/SKy4G/9/

Is this a bug or what? One workaround is to simply capture the keyboard events for "CTRL" and "C" and "V" but in when I do this, Chrome then receives the Copy event Twice. This then requires a lot more code to disable the function in Chrome... and it seems backwards.

Can anyone provide a solution or some insight into why it's not working?

Upvotes: 2

Views: 1707

Answers (2)

Subbu
Subbu

Reputation: 3299

It is working in mozilla too. Mozilla behave little bit differently than chrome. In Mozilla if you select anything on document and then press ctrl+c(/ Right click Copy) it will work. But in chrome it can work without any selection on document.

Upvotes: 0

zgood
zgood

Reputation: 12571

It appears that the FireFox copy event will only fire when text is selected/highlighted.

Upvotes: 3

Related Questions