Prompting user to save file using a 'Save-as' dialog?

后端 未结 2 1026
借酒劲吻你
借酒劲吻你 2021-01-02 15:11

I currently have this code:

function download(filename, text) {
        var pom = document.createElement(\'a\');
        pom.setAttribute(\'href\', \'data:te         


        
相关标签:
2条回答
  • 2021-01-02 15:22

    My browser was set to automatically download all files in default location which is why not only this file but all other files from my browser were downloaded directly without the save prompt dialogue. Changing the settings in browser to 'always ask the download location' worked.

    0 讨论(0)
  • 2021-01-02 15:34

    The only way to do this is to set the header of the file on the server, like so:

    <FilesMatch "\.(?i:pdf)$">
       ForceType application/octet-stream
       Header set Content-Disposition attachment
    </FilesMatch>
    

    The download attribute does not allow you to change the filename or filetype any more as it is an obvious security risk.

    What you are trying to do it replicate the right-click - save-as dialogue but I'm afraid that is not possible at this time.

    0 讨论(0)
提交回复
热议问题