(JavaScript/jQuery): Create dynamically anchor tag and simulate click on that anchor tag automatically.
=================================
var link = document.createElement('a');
link.href = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,' + response.data;
link.download = "report" + GetCurrentDate() + ".xlsx";
//Firefox requires the link to be in the body
document.body.appendChild(link);
//simulate click
link.click();
//remove the link when done
document.body.removeChild(link);
=================================
var GetCurrentDate = function () {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
today = yyyy + '-' + mm + '-' + dd;
return today;
};
=======================================
//quarter = 2018.4, output = FY18 Q4
var GetFormattedQuarter = function (quarter) {
if (quarter) {
return String(quarter).replace(/^..(..).(.)$/, 'FY$1 Q$2');
}
};
==============================
var link = document.createElement('a');
link.href = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,' + response.data;
link.download = "report" + GetCurrentDate() + ".xlsx";
//Firefox requires the link to be in the body
document.body.appendChild(link);
//simulate click
link.click();
//remove the link when done
document.body.removeChild(link);
=================================
var GetCurrentDate = function () {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
today = yyyy + '-' + mm + '-' + dd;
return today;
};
=======================================
//quarter = 2018.4, output = FY18 Q4
var GetFormattedQuarter = function (quarter) {
if (quarter) {
return String(quarter).replace(/^..(..).(.)$/, 'FY$1 Q$2');
}
};
==============================
Comments
Post a Comment