link.click(); does not work in internet explorer while working in chrome

nanobots

I have a program that tracks amount of incidents that happens on a server. I want to beable to export individual incident detail to a csv file and allow users to download it.

I have a button that on the frontpage that looks like this :

<button class="btn btn-main btn-actions-ok" ng-click="exportIncident()">Export Incident</button>

and on the back end code I have an array of array called totaDatarow [];

            $scope.exportIncident = function () {
                var totalDataRow = [];
                var csvContent = "data:text/csv;charset=utf-8,";
                var exportDataHeader = ["Event Type", "User ID", "Event Date", "Description", "DocNum", "Library", "Version", "Comments"]
                totalDataRow.push(exportDataHeader);
                var incident = $scope.incident;
                incident.details.forEach(function (detail) {
                    var exportDatarow = [];
                    //logic to add incident information to exportDatarow
                    totalDataRow.push(exportDatarow);
                })

                totalDataRow.forEach(function (infoArray) {

                    dataString = infoArray.join(",");
                    csvContent = csvContent + "\n" + dataString
                });

                var encodedUri = encodeURI(csvContent);
                var link = document.createElement("a");
                link.setAttribute("href", encodedUri);
                link.setAttribute("download", "Incident_"+ incident.id +".csv");

                link.click();
            }

I did not use window.open because by using that way, I can't find a way to customize the file name of the file that I generated. So I created a link inside the button and click on it to download. In chrome this code works perfectly fine. The csv file is created and downloaded. However in internet explorer this code simply does not work. When I click on the button nothing happens. I ran this through the debugger and found out that when internet explorer reach the link.click(). When it tries to process that line nothing happens.

I need help on this as I don't know whether it is my code issue or is it internet explorer compatibility issue? or something else thanks.

Ason

Internet Explorer doesn't support the download attribute, Edge does though

Check this posts for a workaround:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does this dropdown list for sorting work in Internet Explorer but not in Chrome?

MouseEvent not working in Internet Explorer

.includes() not working in Internet Explorer

Selenium click not working on Internet Explorer 11

Does $() work differently in Internet Explorer?

What would cause click events to stop working in Internet Explorer 11?

OpenLayers: Does not work in internet explorer

GZip Compression Not working in internet explorer 11, but working fine in Chrome & Firefox

Placeholder not working with internet explorer

Java script code not working in Internet Explorer while working perfectly fine in Google Chrome

Does Internet Explorer have something equivalent to Chrome's app mode?

Flot graph not working in Firefox or Internet Explorer, only Chrome

Delete does not work in only Internet Explorer

animate() not working in internet explorer

Right-click tabs doesn't work on Internet Explorer

appendChild not working in internet explorer

Internet Explorer Function Inside a Function Does Not Work

FormData() not working in Firefox and Internet Explorer; only Chrome is OK

vba intercept internet explorer link click

Flexbox works in Internet explorer but does not in Chrome

Mask is not working in Internet explorer

Click link in Internet Explorer

Adding an option to a select does not work in Internet Explorer

Firefox does not display table-row as Chrome and Internet Explorer

I've issue with below image in internet explorer, in chrome it is working

Why does my toggle not work in Internet Explorer?

click on link text in internet explorer using vba

Does JSONata work in internet Explorer?

Form Submission does not work in Internet Explorer - Joomla