In new version of Google Chorme the command dispatchEvent not work well.
In my previous script I saved the file with the following code, but dispatchEvent not work and no file was saved.
var today = new Date();
downloadWithName("data:text/csv;charset=utf-8," + escape(myCsv), "sharePost_" + today.toUTCString() + ".dat");
}
function downloadWithName(uri, name) {
function eventFire(el, etype){
if (el.fireEvent) {
(el.fireEvent('on' + etype));
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
var link = document.createElement("a");;
link.download = name;
link.href = uri;
eventFire(link, "click");
the solution is to change istruction createEvent with MouseEvent:
downloadWithName("data:text/csv;charset=utf-8," + escape(myCsv), "sharePost_" + today.toUTCString() + ".dat");
}
function downloadWithName(uri, name) {
function eventFire(el, etype){
if (el.fireEvent) {
(el.fireEvent('on' + etype));
} else {
//var evObj = document.createEvent('Events');
var evObj = new MouseEvent(etype)
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
var link = document.createElement("a");;
link.download = name;
link.href = uri;
eventFire(link, "click");