I have written the code in .JS file to fetch the data from sharepoint list and display in html table.
Now to take my work for next level I need to export the html table to "Excel". The below code is working fine in google chrome,But I find no luck in IE browser
Can any one help me for what reasons the below code is not getting execute
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#btnExport").click(function(e) {
e.preventDefault();
//getting data from our table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('table_wrapper');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
var a = document.createElement('a');
a.href = data_type + ', ' + table_html;
a.download = 'exported_table_' + Math.floor((Math.random() * 9999999) + 1000000) + '.xls';
a.click();
});
});
</script>
</head>
<body>
<button id="btnExport">Export to xls</button>
<br />
<br />
<div id="table_wrapper">
<table border="1" cellspacing="0" bordercolor="#222" id="list">
<tbody>
<tr class="header">
<th>user_id</th>
<th>firstname</th>
<th>lastname</th>
</tr>
<tr>
<td>1</td>
<td>Alex</td>
<td>Lahevin</td>
</tr>
<tr>
<td>2</td>
<td>Kostas</td>
<td>Krevatas</td>
</tr>
<tr>
<td>3</td>
<td>Alexander</td>
<td>Fakaris</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>