Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unable to get property 'getData' of undefined or null reference" in IE but not Chrome

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.

like image 539
pj2452 Avatar asked Jan 02 '15 06:01

pj2452


2 Answers

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');
}
like image 86
pj2452 Avatar answered Nov 14 '22 04:11

pj2452


In IE, it should be:

var value = event.originalEvent.clipboardData.getData("Text"); 
like image 2
securecodeninja Avatar answered Nov 14 '22 05:11

securecodeninja