Jitendra Vyas Jitendra Vyas - 1 year ago 101
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.

Answer Source

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"');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download