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

前端 未结 4 1056
予麋鹿
予麋鹿 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 07:58

    According to this MDN page (emphasis mine)

    A local file is dragged using the application/x-moz-file type with a data value that is an nsIFile object. Non-privileged web pages are not able to retrieve or modify data of this type.

    So, if you're not writing a browser extension, you can't, and will receive a Security Error.

    What happens when you drag some data to the Desktop is up to your OS (mine converts it to some .textClipping file format).

提交回复
热议问题