Download File Using Javascript/jQuery

前端 未结 28 2875
悲&欢浪女
悲&欢浪女 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:49

    Only seven years later here comes a one line jQuery solution using a form instead of an iframe or link:

    $('
    ') .attr('action', filePath) .appendTo('body').submit().remove();

    I've tested this in

    • Chrome 55
    • Firefox 50
    • Edge IE8-10
    • iOS 10 (Safari/Chrome)
    • Android Chrome

    If anyone knows of any downsides with this solution I'd be very happy to hear about them.


    Full demo:

    
    
    
    
    
    
    

提交回复
热议问题