Jitendra Vyas Jitendra Vyas - 9 months ago 61
PHP Question

Prompt user to download PDF file instead of opening

In my project site, if I click on a link, the PDF opens in a new or parent window. Well I want a box to appear that prompts the user to download the file instead of opening it.

Does anyone know of a simple JavaScript onClick event that will do this, in all browsers, with default settings?

My server is PHP based.


Since your edit states that you're using PHP, here's how to do the same in PHP:

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');