+ 3

Pdf files not getting downloaded in mobile view.

Im trying it in localhost server presently. This is my code for a download button of a pdf in my PC. <a href="file:///C:/Users/senth/Desktop/Website/files/myNotes.pdf" download> <button type="button" class="btn btn-secondary">Download </button> </a> This successfully opens in chrome localhost and displays a preview type pdf where I can see download option in top right but when I inspect and open in mobile view.... Its not opening and nothing is happening. We observe in PC its preview gets opened directly and in mobile it directly gets downloaded but here in mobile view nothing is happening. Does it get downloaded in phone when I upload the website and open in a phone? Pls share other ideas better than this to make my pdf downloadable from my website as we see in any website.

9th Sep 2019, 12:35 PM
Peter Stark
4 Answers
+ 3
Senthil Vikram Do you think it will work if we set the 'href' attribute using relative path? I'm asking this because I see your link reference "file:///..." (file protocol - absolute path) So, assuming the PDF was in "downloads" subdirectory, and HTML document is in root directory, do you think it will work if we change the link reference to "./downloads/myNotes.pdf" ?
11th Sep 2019, 8:27 AM
Ipang
+ 2
The downloaded is not possible with tags, it required some JavaScript
11th Sep 2019, 2:01 AM
Qudusayo
Qudusayo - avatar
+ 2
Qudusayo could you help me in having that JS code?
11th Sep 2019, 4:08 AM
Peter Stark
+ 2
Ipang absolutely no in the first case....But I'm not sure if it works in the second case. As I mentioned that still I did not upload my website, for now.... It should work on file protocol. Im considering the Mobile view in inspect element on my PC. I'm not sure if it gets downloaded in mobile when I put it in downloads subdirectory.
11th Sep 2019, 8:52 PM
Peter Stark