I have this code, but it only works in Chrome, is there any way i can make it work in IE. It should be downloading a CSV file. or if there are any other method that can export csv file using IE10
$('#download').on('click', function () {
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('#example1', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
pom.click();
}
});
<table id="example1" border="1" style="background-color:#FFFFCC" width="0%" cellpadding="3" cellspacing="3">
<tr>
<th>Title</th>
<th>Name</th>
<th>Phone</th>
</tr>
<tr>
<td>Mr.</td>
<td>John</td>
<td>07868785831</td>
</tr>
<tr>
<td>Miss</td>
<td><i>Linda</i></td>
<td>0141-2244-5566</td>
</tr>
<tr>
<td>Master</td>
<td>Jack</td>
<td>0142-1212-1234</td>
</tr></table>
<a href="#" id="download">Download</a>
Here is the JSFIDDLE DEMO
Updated: Example 3.1 works fine but i dont know how can i convert the above code to this: Working Example
UPDATED::
$('#download').on('click', function () {
var csvContent = $('#example1'); //here we load our csv data
var blob = new Blob([csvContent], {
type: "text/csv;charset=utf-8;",
});
navigator.msSaveBlob(blob, "filename.csv")
});
});
i get error 0x800a139e - JavaScript runtime error: InvalidStateError