• Home
  • About
  • Resume

Copy/Paste image into an editable DOM element in Chrome

By , 09/11/2017 4:29 PM

All major browsers allow to paste image directly into a DOM element with contentEditable property set to true. They automatically convert it into IMG element with source pointing to base64 encoded DataURI of the pasted image. That is all browsers, but Chrome. Chrome needs a little help.

In my particular case I need to be able to paste image into an IFRAME with editable body of the content document (for some reason Infragistics WebHtmlEditor ASP.NET control renders itself as this contraption). But the code below applies (with small changes) to any editable DOM element.

To achieve the result we need to perform 3 tasks:

  1. Capture image from the clipboard
  2. Convert the image to DataURI format
  3. Create IMG element with the DataURI source and insert it into the DOM

Take a look at the code below: Continue reading 'Copy/Paste image into an editable DOM element in Chrome'»

Panorama Theme by Themocracy