I want to paste the clipboard content on html page. The content is copied from an ms-word file. Contains text and images. Consider the following code:
<div id="pasteArea" contenteditable="True"></div>
<script type="text/javascript">
var pasteArea = document.getElementById('pasteArea');
pasteArea.onpaste = function (event) {
event.preventDefault();
event.stopPropagation();
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) {
var item = items[index];
if(item.kind === 'string'){
console.log(item.getData('text'));
// Getting the error in here!
}
else if(item.kind === 'file'){
// Code for handling images
}
}
}
</script>
I tried using event.clipboardData.getData('text');
but it fetches the entire text (i.e. skips the images in between) and also the text formatting is lost.
Any idea on how to handle the above case? Thank you.