Phenomenon
In Internet Explorer 11, when pasting images into a contenteditable div, the paste event may not fire as expected. This is particularly problematic in SharePoint Online environments. Additionally, IE11 lacks the clipboardData property in the paste event, making it difficult to access clipboard contents directly.
Reproduction example
- Create a contenteditable div in IE11 (especially in SharePoint).
- Copy an image to clipboard.
- Try to paste the image into the contenteditable div.
- Observe that the
pasteevent may not fire. - Check if image is pasted despite missing event.
Observed behavior
- Paste event not firing:
pasteevent listener may not be triggered. - No clipboardData: IE11 doesn’t provide
clipboardDataproperty in paste event. - Image pasting: Images may still be pasted but event handling fails.
- SharePoint-specific: More common in SharePoint Online environments.
- Base64 data: Pasted images may contain base64 data in
srcattribute.
Expected behavior
pasteevent should fire when pasting images.- Clipboard data should be accessible via
clipboardDataAPI. - Image data should be available for processing.
- Event handling should work consistently.
Analysis
IE11 has limited support for modern clipboard APIs. The browser handles paste events differently, especially for images, and doesn’t provide the same clipboardData interface as modern browsers.
Workarounds
- Extract image data from DOM after paste:
element.addEventListener('paste', function(e) { setTimeout(function() { var images = element.getElementsByTagName('img'); for (var i = 0; i < images.length; i++) { var img = images[i]; var src = img.src; if (src.startsWith('data:image')) { // Handle base64 image data console.log('Base64 Image:', src); } } }, 0); }); - Ensure contenteditable element has focus before paste.
- Use alternative file input for image uploads in IE11.
- Consider polyfills or libraries that handle IE11 clipboard limitations.