How to trigger a file download when clicking an HTML button or JavaScript

前端 未结 21 2915
终归单人心
终归单人心 2020-11-22 05:27

This is crazy but I don\'t know how to do this, and because of how common the words are, it\'s hard to find what I need on search engines. I\'m thinking this should be an ea

21条回答
  •  青春惊慌失措
    2020-11-22 06:10

    If you can't use form, another approach with downloadjs fit nice. Downloadjs use blob and html 5 file API under the hood:

    {downloadjs(url, filename)})/>

    *it's jsx/react syntax, but can be used in pure html

    Note: Edited to fix layout issue above

提交回复
热议问题