Is it possible to write data to file using only JavaScript?

后端 未结 10 1449
梦如初夏
梦如初夏 2020-11-21 15:45

I want to Write Data to existing file using JavaScript. I don\'t want to print it on console. I want to Actually Write data to abc.txt. I read many answered que

10条回答
  •  没有蜡笔的小新
    2020-11-21 16:16

    Try

    let a = document.createElement('a');
    a.href = "data:application/octet-stream,"+encodeURIComponent("My DATA");
    a.download = 'abc.txt';
    a.click();

    If you want to download binary data look here

    Update

    2020.06.14 I upgrade Chrome to 83.0 and above SO snippet stop works (reason: sandbox security restrictions) - but JSFiddle version works - here

提交回复
热议问题