0

I'm trying to make a simple page with JS which generates Batch Scrips based on user input. This is the prototype code and works fine with Chrome, but clicking on link with Firefox downloads the file as .txt (e.g.: file.bat.txt) and IE is completey unresponsive to the link Where am i going wrong? Any issues with "data:text/plain;base64,"?

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<body>
<a href="#" download="file.bat">click here</a>
<script>
var bat_source = "@echo off\necho Hello world\npause";
document.querySelector("a").href = 'data:text/plain;base64,' + btoa(bat_source);
</script>
</body>
</html>
cht
  • 319
  • 3
  • 13
  • 1
    https://stackoverflow.com/a/26996264/1683264 – rojo Jun 28 '17 at 23:31
  • Thanks dude, setting 'data:text/bat;base64,' did the job for Firefox. IE still seems unresponsive, but that's okay. – cht Jun 29 '17 at 06:28
  • By default Internet Explorer blocks JavaScript from running from local, non-HTTP-served files. You might consider [rewriting your project as an .hta file](https://stackoverflow.com/a/40289936/1683264). – rojo Jun 29 '17 at 12:12

0 Answers0