I tried below code and run it. It seems I can create ClipboardEvent successfully to copy information. But, I could not paste it using Ctrl+V in MS Word.
Browser : Firefox (v35.0.1)
// behavior to copy elements with format
$("#copy-formatted").click(function(e){
var text = $("#container").html();
console.log(text);
// first attempt => data is successfully saved to copyEvent
/*var copyEvent = new ClipboardEvent('copy', { dataType: 'text/plain', data: text } );
console.log(copyEvent);
document.dispatchEvent(copyEvent);*/
// ClipboardEvent is not recognized by IE11
var clip = new ClipboardEvent('copy');
clip.clipboardData.setData('text/plain', "test");
clip.preventDefault();
clip.returnValue = false;
// *********************************** //
// data is successfully retrieved here //
// *********************************** //
console.log(clip.clipboardData.getData('text/plain'));
// *** > dispatching not sure how this works. seems not working.
//e.target.dispatchEvent(clip);
document.dispatchEvent(clip);
console.log("finished dispatching event");
});
Please help.