View Full Version : How do i initiate a download on page load?
i-CONICA
06-03-2008, 10:24 PM
Hi, I have a downloads site and I'd like to be able to have the users click the download button which takes them to a "your download will start shortly" page, where the file they clicked "download" on will start downloading straight away.
These pages will be unique to the piece of software and the whole site is simple html.
So the idea is they go to the download page for that software, click download and are taken to another page where their download will begin, this gives me more room for ad space and further software download mirror if the first fails.
Thanks.
Horus_Kol
06-03-2008, 11:45 PM
probably just make an ajax type request...
using the prototype library, this would simply be:
<script type="text/javascript">
new Ajax.request('url to file');
</script>
i-CONICA
06-04-2008, 02:02 AM
Whoa, Ajax is one of those words that sends shivers down my spine, I know html xhtml css, some JavaScript and some php.
Is it as simple as pasting that into the head of the page? Replacing "url to file" with the necessary info...?
So then when the page loads the download dialogue box will be displayed for the file specified?
If I've understood that right and that's what that will do then Thank you sooo much.
Horus_Kol
06-04-2008, 03:27 AM
not quite - for that code to work, you will need to add the prototype (www.prototypejs.com) JS framework - but that is a simple as copying their .js file to your site, and having:
<script type="text/javascript" src="path/to/prototype.js"></script>
<script type="text/javascript">
new Ajax.request('url to file');
</script>
then, yeah, the 'url to file' should be that simple...
prototype just takes the dull bit out of a lot of javascript (like Ajax)
i-CONICA
06-04-2008, 05:05 AM
Thanks dude, you rock!
i-CONICA
06-04-2008, 05:07 AM
PS. I just twigged that this should work also.
<meta content="5; URL=../../../software/antivirus/avg-av/avg_free_stf_en_8_100a1295.exe" http-equiv="Refresh" />
Is there any pros/cons between your method and the meta tag method?
Thanks
Horus_Kol
06-04-2008, 08:37 AM
actually - sorry.. that ajax request won't work (actually got around to trying it)
your solution... yeah, that would work...
i-CONICA
06-06-2008, 02:43 PM
Just to clarify before i put this into action. Is there any instance where the meta tag won't initiate the download?
It works perfectly so far, but do any browsers ignore it? Or if a certain page element fails to load such as an external img....
I'm thinking because I don't want to have a "If nothing happens click here" button to start it manually because people will just click that anyway. bypassing my 5 second delay...
I understand sites only have that link to start it manually to point at another server, incase the first one is too busy. I have only one so that's irrelevant.
Thanks.
Horus_Kol
06-07-2008, 08:10 AM
no, they have it in case the meta doesn't work, too... just let the user know "the download should start automatically, click here if it doesn't"
people are used to that, so they will wait a few seconds
RysChwith
06-09-2008, 08:26 AM
There are no browsers that block them by default, but some do include the option to disable meta redirects (pretty sure Firefox does, if no one else).
Rys
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.