"Cannot get property" getData "from undefined or null reference" in IE but not in Chrome

Thanks to the help of another participant, I successfully implemented the JS method, which has the ability to insert Excel data and break it into the form of an HTML text field table ( see thread ).

The problem that I am facing now is that it only works in Chrome, and IE10 and IE11 have the following error:

"Cannot get getData property from undefined or null reference.

This error occurs in the second 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 } 

I wonder if anyone can see the problem of why Chrome is satisfied while IE is not working.

+5
source share
2 answers

The answer is found here: Intercept event in Javascript

It 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'); } 
+4
source

In IE, this should be :

 var value = event.originalEvent.clipboardData.getData("Text"); 
+3
source

Source: https://habr.com/ru/post/1210238/


All Articles