E
E
Egor2015-01-08 16:34:42
Internet Explorer
Egor, 2015-01-08 16:34:42

How to programmatically click on a newly created link in IE 11?

Greetings.
There is such a code

var link = document.createElement('a');

                        angular.element(link)
                            .attr('href', dataUrl)
                            .attr('download', fileName);

                        if (document.createEvent) {
                            alert('createEvent');
                            var event = document.createEvent("MouseEvents");
                            event.initEvent("click", true, true);
                            link.dispatchEvent(event);
                        }else if (link.click()) {
                            alert('click');
                            link.click();
                        }

Works in all browsers, does not want to in IE. Alert 'createEvent' appears, but there is no file download window. Tell me how to fix it or where to read about it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
ycexa, 2015-01-09
@ycexa

If
then
But still will not work - you must first add a node to the DOM.
In general, downloading a file without the knowledge of the user is bad :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question