Causing File Download on Page Load (Javascript?)

J

Jonathan Wood

Greetings,

I'm creating a shareware site and I want the download page to initiate
downloading a file when it loads.

After thinking about this, it seemed like javascript was the best way to do
this. So I tried creating a startup script that used window.open(), but this
causes most browsers to report a pop-up was attempted. So I changed it to
window.location.href. This works but, on some browsers, the page doesn't
finish loading. So I changed it to
setTimeout("window.location.href='url'",1500), which waits a moment before
performing the download.

This last approach appears to work. I also include a download link in case
javascript is not enabled. But I'm feeling a bit unsure of myself.

Does this seem like the best approach? I'm a little concerned impatient
users might click the link when it doesn't start downloading immediately.
Also, I'm not clear on when the browser decides to continue showing the
current page after setting window.location.href (as it generally appears to
do when I set the URL to a downloadable file).

Any tips appreciated.

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top