/    Sign up×
Community /Pin to ProfileBookmark

How do I force an open/save dialogue on a download?

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.

to post a comment
HTML

6 Comments(s)

Copy linkTweet thisAlerts:
@GarySMay 21.2006 — Can be done with (for example) PHP by sending header information. Not sure it can be done with pure HTML, though.
Copy linkTweet thisAlerts:
@ray326May 22.2006 — 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.
Copy linkTweet thisAlerts:
@slaughtersMay 22.2006 — 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[CODE]<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>[/CODE]
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:&lt;META HTTP-EQUIV="Content-Disposition" CONTENT="attachment; filename=whatever.pdf"&gt;
Copy linkTweet thisAlerts:
@Robert_WellockMay 22.2006 — Apache .htaccess: ForceType application/octet-stream pdf
Copy linkTweet thisAlerts:
@nattrillauthorMay 24.2006 — Thankyou, i'll try it soon.
Copy linkTweet thisAlerts:
@ray326May 25.2006 — Even with an application/octet-stream header IE may decide to "sniff" the response content and act according to the user's PDF binding.
×

Success!

Help @nattrill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...