Click to See Complete Forum and Search --> : How do I force an open/save dialogue on a download?


nattrill
05-21-2006, 09:32 AM
Hi,

Basically i've got a pdf file that I want people to access as a download. When you click on it, it will automatically open the file for you. But I want it to display the open/save dialogue that you get when downloading a zip or unknown file type.

It is for a website that I am making for my church, so I want to make it as easy to use as possible. So I don’t to put the file in a zip, or expect people to know how to right click and select ‘save target as’.

Is there an easy way of doing this? Perhaps something to do with target= something?

Thanks for any help you can give!

Neil.

GaryS
05-21-2006, 09:44 AM
Can be done with (for example) PHP by sending header information. Not sure it can be done with pure HTML, though.

ray326
05-21-2006, 11:10 PM
The easy way is to zip it up. Nothing can be done in HTML to force and even sending headers may not work in IE.

slaughters
05-22-2006, 11:58 AM
I did some quick Googling and there appears to be 2 different ways to do this. (I have not tried either). One is a JavaScript approach which looks to be IE specific<html>
<body>
<script>
function downloadme(x){
myTempWindow = window.open(x,’’,’left=10000,screenX=10000’);
myTempWindow.document.execCommand(’SaveAs’,’null’,x);
myTempWindow.close();
}
</script>

<a href=javascript:downloadme("whatever.pdf");>Download this pdf</a>
</body>
</html>For the other you can force the browser to display a "Save As/Open from current location" dialogue box when it wants to write known binary content to the client.

The official approach for this is to use a http header to request the display of user permission dialog box. This header is known as "Content-Disposition."

Following is the sample for server-side based applications, (almost all http libraries provide an API to set an http header).

HttpResponse.setHeader("Content-Disposition "," attachment; filename= whatever.pdf");

I beleive you can even force Content-Disposition to fit in a meta tag if you don't have the ability to issue server side commands. Something like:<META HTTP-EQUIV="Content-Disposition" CONTENT="attachment; filename=whatever.pdf">

Robert Wellock
05-22-2006, 01:14 PM
Apache .htaccess: ForceType application/octet-stream pdf

nattrill
05-24-2006, 01:05 PM
Thankyou, i'll try it soon.

ray326
05-24-2006, 09:49 PM
Even with an application/octet-stream header IE may decide to "sniff" the response content and act according to the user's PDF binding.