HTML drag/drop - how to set the filename of an *outgoing* drag (to desktop)

前端 未结 4 1053
予麋鹿
予麋鹿 2021-02-19 07:11

I\'m trying to make it so a user can drag an icon from the web browser to their desktop, and a text file is created. I\'ve got the content part down, but I can\'t figure out how

4条回答
  •  既然无缘
    2021-02-19 08:07

    Argh! The below works fine in Chrome:

    const jsonData = JSON.stringify(dat);
    event.dataTransfer.setData("DownloadURL", "application/json:crashdump.json:data:application/json;charset=utf-8," + jsonData);
    

    Though not in Safari nor Firefox. What a huge bummer.

提交回复
热议问题