Jitendra Vyas Jitendra Vyas - 4 months ago 14x
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"');