Thursday, April 12, 2007

How To: Redirect After Download

Don't!

I don't think you can. I googled a bit and gave up. Then I decided to check a page where I've seen it done: Source Forge. Turns out that they cheated!

So, the answer is still "don't", however, we can do what SF does and...fake it!

What I want to happen:
  1. Our user sees a link to a download and clicks it.
  2. The Save As... dialog appears and the user selects the location.
  3. The browser displays a "Thank You" page while the download finishes in the download window.

How to Fake it:
  1. Our user sees a link to a download and clicks it.
  2. The link takes the user to the "Thank You" page. The "Thank You" has an iFrame whose src attribute is the real download link.
  3. The Save As... dialog appears and the user selects the location.
  4. The download finishes while the user views the "Thank You" page.

Discussion:

There could be compatibility issues with an iFrame in mobile or really old browsers. Some alternatives might be:
  • Use a <meta> tag refresh pointing to the real download link and a time of 0 (zero).
  • Try a Javascript redirect.
But the idea is to fake it by displaying the "Thank You" page first and then starting the download.

If all else fails just rethink your download flow. The user clicks the download link. He gets the "Thank You" page which has a very clear, front and center link that says "Begin Your Download by clicking here" or something that says "I'm really sorry you have to click twice (it's not my fault you use a lame browser) so please accept this flattering compliment (to help avoid the total destruction of the world (and I'm sorry your self-esteem is so fragile))."

1 comment:

  1. the meta refresh tag and a time of about 3 seconds normally works the best. sf.net uses an iframe for their mirror selection process I believe.

    You know, if you wanted to be really awesome about it, you'd have an httpmodule serving downloads, identified by download 'ticket', and you'd be able to session the download's completion by the client, add a little ajax and you could have the 'thanks for downloading' page refresh on download completion, perhaps to a 'success' page with install instructions for eg.

    ReplyDelete