KNN
KNN

Reputation: 1

addEventListener does not work on init (IE)?

I am trying to add an EventListener on the body tag, which works fine on Chrome, but not on Internet Explorer (Edge). See code below. However, it works in IE, but only after I select an input textbox. But I don't want to select an input textbox first, the EventListener should listen immediately after I load the page.. What am I doing wrong here?

document.getElementsByTagName('body')[0].addEventListener('paste', function() {
     console.log('hi');
});

Upvotes: 0

Views: 53

Answers (1)

Quentin
Quentin

Reputation: 943470

This is a known limitation of Internet Explorer. It:

Only fires copy event on a valid selection and only cut and paste in focused editable fields.

You are doing nothing wrong.

Since you haven't focused an element (e.g. with autofocus), no editable field will have the focus just after the document has loaded.

Keep in mind that IE11 is not a browser under active development. It continues to exist primarily for compatibility with ancient Intranet applications. Not with modern web applications.

Upvotes: 1

Related Questions