In my website I have a javascript in which I wish to open a file save dialog. The purpose is to save in a text file some data that are coming from the web server.
I am trying to use the code snippet shown in this post:
[Using HTML5/JavaScript to generate and save a file
And to be precise:
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
}
else {
pom.click();
}
}
This works great for Firefox and Chrome. However with Internet Explorer 11 it doesn't work. When this instruction is executed...
pom.dispatchEvent(event);
...nothing happens. The save dialog is not opened, and no error is shown in the java console of the browser. The event seems to get lost in the void. Any help would be greatly appreciated.