Download File Using Javascript/jQuery

前端 未结 28 2882
悲&欢浪女
悲&欢浪女 2020-11-21 05:11

I have a very similar requirement specified here.

I need to have the user\'s browser start a download manually when $(\'a#someID\').click();

But

28条回答
  •  天涯浪人
    2020-11-21 05:57

    I don't know if the question is just too old, but setting window.location to a download url will work, as long as the download mime type is correct (for example a zip archive).

    var download = function(downloadURL) {
    
       location = downloadURL;
    
    });
    
    download('http://example.com/archive.zip'); //correct usage
    download('http://example.com/page.html'); //DON'T
    

提交回复
热议问题