How can i change my file name of download from the code below
<script type="text/javascript" src="https://code.jquery.com/jquery-
1.9.0.js"> </script>
<script type="text/javascript">
$(function(){
$('#button').click(function(){
var url='data:application/vnd.ms-excel,' +
encodeURIComponent($('#tableWrap').html())
location.href=url
return false
})
})
</script>
Here is the fiddle to download the excel with different file name. https://jsfiddle.net/cqm2psgs/1/
<div id="tableWrap">
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
</div>
<button name="click me" id="button">Click me</button>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"> </script>
<script type="text/javascript">
$(function(){
$('#button').click(function(){
var urrl='data:application/vnd.ms-excel,' + encodeURIComponent($('#tableWrap').html());
var link=document.createElement("a");
link.href=urrl;
link.download= "filename.xls";
document.body.appendChild(link);
link.click();
link.body.removeChild(link);
return false;
});
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.