views:

42

answers:

3

Whats the best method to prompt a user to download something? In the past I've used window.open('file.pdf'); but I can see popup blockers having a problem with this. Of course I'll include a manual link aswel.

I basically want something like the Microsoft Download page. So whats the script that prompts this?

A: 

Set a content disposition header with an attachment value

David Dorward
Done, but that wasn't my question
m.edmondson
+1  A: 
Content-Disposition: attachment; filename="file.pdf"

To do this you may want to pass your file.pdf through a server script that forces that header on it.

What you see on that download page is just a location change. And if that page returns the download header the browser won't change page.

Alin Purcaru
+3  A: 

Redirect using javascript.

function redirect() {
window.location = 'http://www.url.to/your.file';
}
Joachim VR