1

I am creating a download file using javascript. It works fine so long as I don't put the # character in the file (I'm using chromium 80.0.3987.149 on debian 10.3). But if I do put a # in the content, then it does not work:

<a id="savex" download="x">click to save</a>

var saveButton = document.getElementById('savex');
saveButton.setAttribute('href-lang', 'text/plain');
var x = [];
var working = true;
for (var i = 0; i < 10; i++) {
  x.push((working ? '' : '#') + 'test' + i);
}
var content = x.join(' ');
saveButton.href = 'data:text/plain;utf8,' + content;

Here is a fiddle: https://jsfiddle.net/zx2t67mw/

I'm guessing that the # needs escaping somehow. And I'm guessing there are other similar characters that also need escaping if I want to see them in the output file.

What should I change in my code to be able to see # in the resulting download file?

mulllhausen
  • 4,225
  • 7
  • 49
  • 71

0 Answers0