7

Thanks to the help of another member I have successfully implemented a JS method that has the ability to paste excel data and split it into an HTML textbox table form (see thread).

The issue that I am now faced with is that this is only functional in Chrome, while IE10 and IE11 both flag the following error:

"Unable to get property 'getData' of undefined or null reference."

This error is thrown in the 2nd line of the function (below):

function (event) {
    var input_id = $(this).attr("id");
    var value = event.originalEvent.clipboardData.getData('text/plain'); //ERROR in IE
    /* ... */
    event.preventDefault(); // prevent the original paste
}

Wondering if anyone can see the issue at hand with why Chrome is satisfied while IE is not.

Community
  • 1
  • 1
pj2452
  • 905
  • 3
  • 10
  • 22
  • This question actually solved my issue: http://stackoverflow.com/questions/6035071/intercept-paste-event-in-javascript Thank you for the help! – pj2452 Jan 03 '15 at 20:27

2 Answers2

12

Answer found here: Intercept paste event in Javascript

This worked for me.

if (window.clipboardData && window.clipboardData.getData) { // IE
    pastedText = window.clipboardData.getData('Text');
}
else if (event.originalEvent.clipboardData && event.originalEvent.clipboardData.getData) { // other browsers
    pastedText = event.originalEvent.clipboardData.getData('text/plain');
}
Community
  • 1
  • 1
pj2452
  • 905
  • 3
  • 10
  • 22
  • 1
    This actually is the correct answer for this question, thanks pj2452, it looks like the clipboardData from the event handler comes as null for internet explorer. – Leo Mar 06 '18 at 10:38
2

In IE, it should be:

var value = event.originalEvent.clipboardData.getData("Text"); 
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
securecodeninja
  • 2,497
  • 3
  • 16
  • 22