Forum Moderators: open

Message Too Old, No Replies

Script to start downloading a file automatically, NOT a redirect?

I'm trying to have a file automatically download without using a redirect.

         

dpaanlka

12:09 am on Mar 30, 2009 (gmt 0)

10+ Year Member



Anybody have any ideas how, using JavaScript, I might be able to launch a file download as a user enters a page (a page that says Thanks for downloading!) but NOT redirecting the user from that page.

The reason is because AdSense doesn't like page redirects, and since this is the highest trafficked page on my site (thanks to other sites linking to it) I don't want to waste the opportunity.

Thanks in advance!

EDIT: Or if anyone can think of a better way to do it.

noyearzero

1:47 pm on Mar 30, 2009 (gmt 0)

10+ Year Member



this goes in your head of the page...

<meta http-equiv="Refresh" content="0; URL=http://domain.com/script.php"/>

then your script.php file sends the appropriate headers telling the browser it is going to be a file, and then you output the file.

I only know how to do this with PHP, so you'll have to dig up how to do this with your server side language

dpaanlka

4:11 pm on Apr 3, 2009 (gmt 0)

10+ Year Member



If anyone is still interested, I figured out a solution around this that doesn't required scripting at all... simply put the link to the download inside a hidden iFrame. Tadaa!