Owais Ahmed
Owais Ahmed

Reputation: 1438

Download link not working on internet explorer

Hi I am getting an error on IE

TypeError: Object doesn't support this action

This is the code which is failing on IE but working fine on other browsers.

 var link = document.createElement('a');
            link.href = url;
            link.download = 'file';
            link.dispatchEvent(new MouseEvent('click'));

The problem is on the link.dispatchEvent line.

Can anyone please help me to get it working?

Upvotes: 0

Views: 97

Answers (1)

Ashen Gunaratne
Ashen Gunaratne

Reputation: 455

The older versions of IE only supports an proprietary equivalent EventTarget.fireEvent() method and therefore consider using HTMLElement.click() which is fully supported by all IE versions.

Upvotes: 1

Related Questions