1

I created chrome webapp to access the clipboard data.After added my webapp I have the permission to access the clipboard, but I don't know how to get the image from clipboard by clicking the paste button in my page. I just tried to paste an image in google drive presentation file.It shows to install the GoogleDrive webapp.After installing GoogleDrive webapp it allows us to get the image/text from the clipboard by clicking the paste button in edit menu.I want to know how Google Drive get clipboard data using paste button.

Barani
  • 552
  • 4
  • 18

1 Answers1

0

If you request the clipboardRead permission, you can use document.execCommand("paste").

A good explanation for how to do that is https://stackoverflow.com/a/7147192/689161

Edit: some sample code

background.html

<div id="idk" contenteditable="true"></div>

background.js

function paste() {
    var div = document.getElementById("idk");
    div.focus();
    document.execCommand("paste");

    // you can now access whatever was pasted through div.innerHTML
    console.log(div.innerHTML);
}

If the user pastes an image, it'll show up as something like <img src="..."/> and you can extract that for use in your application.

Community
  • 1
  • 1
gengkev
  • 1,890
  • 2
  • 20
  • 31
  • Hi gengkev, thank you for your response. I already tried this code, but it only useful to get clipboard text not images. Have I missed something? – Barani Nov 23 '12 at 10:59
  • I think if you use a contenteditable, you can paste images, too. Does your application already handle pasting using Ctrl+V? – gengkev Nov 24 '12 at 19:48
  • Yes, I already done pasting using Ctrl+V in HTML5.Your code works perfectly.Thank you for valuable response gengkev. – Barani Nov 30 '12 at 11:42