About downloading pdf files with jquery/Javascript

I am downloading PDF file with below code. It works pretty well
It also shows the downloading icon next to the button. Buddha works fine.

function pdf_dow(butonid, url_link, dosya_adi) {

// Code showing the downloading icon next to the button while downloading the file
    var setLoading = function () {
        var search = $("#" + butonid + "");
        if (!search.data('normal-text')) {
            search.data('normal-text', search.html());

    var clearLoading = function () {
        var search = $("#" + butonid + "");

// File download code
        .then(resp => resp.blob())
        .then(blob => {
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            //a.style.display = 'none';
            a.href = url;
            // istediğiniz dosya adı
            a.download = dosya_adi + ".pdf";
        .catch(() => alert('PDF Dosya indirmede bir hata oluştu\nLütfen tekrar deneyin\nSorun devam ederse yöneticiye bildirin!'));


Problem downloading pdf on phone

When the PDF file is downloaded with the code above, the phone screen below shows an icon on the top of the phone as shown in the picture.
This icon may be overlooked by the user, causing them to think that the PDF file has not been downloaded.

The phone screen below in the notification panel looks as shown in the picture

I want the PDF file to be downloaded as shown in the phone screenshot below
How to make a change in the code to download the PDF file as shown in the image below

Thank you

Adem, normally you would not download PDF’s on a phone. Instead, you would just open the PDF in the phone’s browser. Why do you need to download files onto a phone? Do you mean you want to view them on the phone?

There is a button to download or view the PDF when the quote is produced

If you click the button to download or view the PDF using the code below, the “open with” option appears as in the last image above

function pdfd_ownload() {
    window.location.href = "dompdf.php?pdfd_ownload=15";

However, when the button is clicked using the code above, the “open with” option does not appear.

It is not correct to look at the price offer on the browser screen and close it. Your offer should be downloaded to the phone as this is now a generated quote document

I’m worried that the reason I want the “open with” window to appear is because the user may not realize that the PDF file has been downloaded

In this way, when the button is clicked, the PDF file is automatically “download” to the download folder.
My phone is LG G6

I’m not very insistent, if it is possible

This may vary by browser, right? It never occurred to me :grinning: :grinning:

Is it spelled correctly? ?pdfd_ownload= or should it be ?pdf_download= ???

Well, browser do not matter really in this case. Most all browsers on all phones can open PDF’s.
But, a phone user may not want to download items onto them phone inside folders. A lot of phone users do not know where to look for folders on their phones. Remember, you know your phone as an expert, but, others do not. Makes more sense just to open the PDF so it can be viewed.

Here is a link that shows what most phone users need to do to save a PDF on their phone:
save a PDF on your phone Lots of steps for the average user. Hard to duplicate in PHP code!

:grinning: :grinning: :grinning:I wrote wrong here, this is true pdf_download

Yes it can, no problem here

I agree with your opinion 100% and it is true.
But no ordinary user will use it, It is not a situation where a user producing a price offer would want to view the offer as a PDF on the browser and close it.
A user producing a quote must have this document in hand or it is not possible to remember that much information.
If the user does not want to download the PDF file to his phone, there is a button to send it to the e-mail address he gave when starting to issue a price offer.

Actually, you’re right,
it might be more accurate to open pdf in new tab just for phone

Could you consuder keeping the PDFs on your server, and give the user a link (URL) to view the PDF?
This way, you can keep a record of each time they view the PDF (if you need proof of viewing) and it will always be available to them in the future.
Just a thought - hope it helps, but don’t worry if it doesn’t!

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service