7

Can someone explain how does this website accesses the contents of the clipboard and displays it?

http://snag.gy

I am working on a similar project and need to make use of this functionality where users can ctrl+v paste an image. Also, if the site is using Java plug-in, why doesn't my chrome pop up out-of-date warning?

Any help is appreciated!

Thank you.

Alvin
  • 265
  • 1
  • 13
  • 1
    lassebunk.dk/downloads/PasteImageApplet.zip try this out – Abhay Kumar Dec 21 '11 at 04:46
  • I did try their online demo... http://lassebunk.dk/demos/clipboard-image/clipboard-image.html ... but it still pops up the out of date plugin dailog on chrome. Also, according to the main page http://lassebunk.dk/2009/08/04/clipboard-java-applet/ The applet needs to be digitally signed by sun to access the clipboard and has expired on Jan 19th 2010. Any ideas on how the stated website overcomes all that? – Alvin Dec 21 '11 at 04:49

1 Answers1

1

You should be able to tell that by looking at the source (http://snag.gy/assets/js/index.min.js). The code will be unreadable since it's minified, but you can make it readable with a code beautifier (such as http://jsbeautifier.org/).

It uses a java applet to read your clipboard (it's adding it to the page dynamically). It also contains a reference to http://code.google.com/p/zeroclipboard/ which is a flash-based solution mentioned here . I saw that it also makes use of the clipboardData object.

Looks like there are several fallbacks depending on the browser, and also it uses different mechanisms based on the origin of the copied data. You could start with How does the paste image from clipboard functionality work in Gmail and Google Chrome 12+? and fallback to a java applet if the browser is older.

Community
  • 1
  • 1
Matias
  • 4,896
  • 3
  • 28
  • 46
  • Thank you Matias... like you said, it looks like they are using multiple ways to achieve this. First, the html5 method for chrome, then falling back to the applet for firefox and internet explorer. Looks like I din't know about the chrome's new html5 feature which is why it seemed a mystery to me. Once again, thank you looking into it and pointing me in the right direction. Have a wonderful day! – Alvin Dec 21 '11 at 06:45