Force download a pdf link using javascript/ajax/jquery

前端 未结 7 1989
夕颜
夕颜 2020-11-27 04:51

suppose we have a pdf link \"http://manuals.info.apple.com/en/iphone_user_guide.pdf\"(just for example and to let u know that file is not on my server, i only have the link)

相关标签:
7条回答
  • 2020-11-27 05:37

    In javascript use the preventDefault() method of the event args parameter.

    <a href="no-script.html">Download now!</a>
    
    $('a').click(function(e) {
        e.preventDefault(); // stop the browser from following
        window.location.href = 'downloads/file.pdf';
    });
    
    0 讨论(0)
提交回复
热议问题