3

I need to be able to detect the paste event. It is centered around images for the most part, but as of now I will accept anything that will detect the event.

I have successfully had 99% of all posted solutions work for Chrome, but that is it. Even the ones that are stating they work for IE, Firefox and more they do not.

If someone can just point me in a direction that they have successfully used to just detect the paste event and have either a console log or alert occur that would be excellent.

I'm not sure if this will make sense, but an on DOCUMENT paste would be ideal as I would not like to specify the paste area.

EDIT: The research that I have done for this has been finding a multitude of options that use .bind() and .on() in conjunction with 'paste'. However, paste event does not seem to fire in IE or Firefox. They work in Chrome, but it is unclear to me on why this is the case.

Cayce K
  • 2,288
  • 1
  • 22
  • 35
  • I fail to understand how images relate to this. Can you elaborate? – Frédéric Hamidi Aug 04 '14 at 14:03
  • So the idea is using a DROPZONE or something along those lines for files. I have that working. But if they need to paste a screenshot for example by using PRTSCN then they can just hit PRTSCN then paste into area w/o using an image editor. – Cayce K Aug 04 '14 at 14:04
  • Once I can detect the actual paste event in all browsers I may be able to tie in the rest of the functions to actually capture image and so on so forth. Right now I just want to be able to detect the paste event in Firefox, Chrome and IE11. – Cayce K Aug 04 '14 at 14:05
  • Alas, the DOM's standard event for this (the [paste](https://developer.mozilla.org/en-US/docs/Web/Events/paste) event) is only supported by Firefox and Chrome (so far). I do not know of any workaround that does not imply running an add-on or plugin. – Frédéric Hamidi Aug 04 '14 at 14:07
  • By chance would you be able to provide your own example ... or even an example from a source on how to use. I have used it for other situations, but sadly it has not worked in Firefox. Just Chrome. – Cayce K Aug 04 '14 at 14:09
  • possible duplicate of [Paste event in Javascript](http://stackoverflow.com/questions/10833836/paste-event-in-javascript) – Jason Aug 04 '14 at 14:13
  • There are multiple of these, but none have been answered within a period of a year that actually answers the question with an updated response. Many use .bind() and .on() with paste as this ones top answer does and those do not work cross browser as I am asking. Also it is specific to right click paste where I would like it to be both if possible, but am not being picky. – Cayce K Aug 04 '14 at 14:16
  • This is not a duplicate as the mentioned potential duplicate only works with text AND relies on an element with an ID. Please read both questions and answers provided do not work for Firefox. – Cayce K Aug 04 '14 at 14:31

1 Answers1

3

You can use the Clipboard API.

http://caniuse.com/clipboard

and then use .getAsFile() as described here: https://stackoverflow.com/a/6338207/1052033

Community
  • 1
  • 1
Antoine
  • 5,504
  • 5
  • 33
  • 54
  • I have not stumbled or found this type of answer. I will be attempting it now. Once I see how if I can get a response I will set your answer to correct. By any chance have you used this personally? – Cayce K Aug 04 '14 at 14:17
  • 1
    I'm accepting your answer as it also allows me to accept images into it, but it still only works for Chrome... Thank you for your submission, but Jason ruined the post by flagging this thread... If another user comes along and provides a better answer I may review it at that time and decide what is best for the community. – Cayce K Aug 04 '14 at 14:42