[英]generate a batch(.bat) file using javascript or html
Can I make a .bat file using html or javascript so the .the bat file will start to download. 我可以使用html或javascript制作.bat文件,以便.the bat文件开始下载。
I have alredy try 我已经尝试过了
<a href="data:text/plain;charset=utf-8,echo Hello echo world" download="hello-world.bat">clicking here</a>
Well this create a .bat file but between echo Hello
and echo world
I need a new line to make the .bat file correct 好吧,这会创建一个.bat文件,但在
echo Hello
和echo world
我需要一个新行来使.bat文件正确
You could add newline \\n
caracters to your .bat
source string, encode it to base64 and set the href
property of the <a>
tag using javascript : 您可以在
.bat
源字符串中添加换行符 \\n
caracters,将其编码为base64并使用javascript设置<a>
标记的href
属性:
<a href="#" download="hello-world.bat">click here</a>
<script>
var bat_source = "echo Hello\necho world";
document.querySelector("a").href = 'data:text/plain;base64,' + btoa(bat_source);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.