1

I am writing a script which shall download a pdf instead of showing it. I am using Firefox as a webbrowser (latest version) and I installed greasemonkey (latest version) and I am using the Ubuntu OS (14.04).

This is the function I wrote:

function downloadFile(finalURL){
    // Create new (invisible) link:
    var link = document.createElement('a');
    link.href = finalURL;
    link.download = 'test.pdf';
    document.body.appendChild(link);
    link.click();
}

However, the browser still shows the file instead of popping up the "Save as"-Dialogue.

I don't know what I am doing wrong...

Anyone who knows how to fix this?

Thanks in advance!

Franz
  • 49
  • 6
  • You may have to disable `PDFjs` – guest271314 Feb 25 '16 at 18:44
  • If I disable PDFjs it always downloads it. However I want the script to create download-links and if I click on them without my script enabled they shall be displayed in the browser, so this is unfortunately not the solution. – Franz Feb 25 '16 at 19:19
  • See http://stackoverflow.com/questions/20830309/download-file-using-an-ajax-request – Steven Lambert Feb 25 '16 at 20:03

0 Answers0