https://codepen.io/kostas-krevatas/pen/mJyBwp
<button id="exl">Download</button>
<div class="admin_table_form" id="content">
<table class='admin_table'>
jQuery(document).ready(function() {
jQuery("#exl").click(function(e) {
e.preventDefault();
//getting data from our table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('content');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
var a = document.createElement('a');
document.body.appendChild(a); // You need to add this line to work in mozilla
a.href = data_type + ', ' +
table_html;
a.download = 'exported_table_' + Math.floor((Math.random() * 9999999) + 1000000) + '.xls';
a.click();
});
});
<button id="exl">Download</button>
<div class="admin_table_form" id="content">
<table class='admin_table'>
jQuery(document).ready(function() {
jQuery("#exl").click(function(e) {
e.preventDefault();
//getting data from our table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('content');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
var a = document.createElement('a');
document.body.appendChild(a); // You need to add this line to work in mozilla
a.href = data_type + ', ' +
table_html;
a.download = 'exported_table_' + Math.floor((Math.random() * 9999999) + 1000000) + '.xls';
a.click();
});
});
No comments:
Post a Comment