Using the following code from Using HTML5/JavaScript to generate and save a file :
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();
}
}
download('test.txt', 'Hello world!');
I also used a blob but no luck:
var fileContent = String.raw`test`;
var fileName = 'sampleFile.txt';
const blob = new Blob([fileContent], { type: 'text/plain' });
const a = document.createElement('a');
a.setAttribute('download', fileName);
a.setAttribute('href', window.URL.createObjectURL(blob));
a.click();
I am encountering a limit on downloading a string to a file through a hyperlink. I have found in Chrome that if the amount of characters exceed 65535 the hyperlink disappears or on firefox, a 0 bytes file is downloaded.
Is there a way to circumvent this limit? Or perhaps a different way in pure javascript/html to download the file where this limit doesn't exist or is increased?