Site logo

Archived topic

Download file on page load

1 reply · Started by Matt on October 24, 2021

Viewing posts 1–2 of 2

I offer a free trial of my software and I have them confirm their email address before downloading. When they click the confirm button it takes them to a webpage to download but I'd like the .zip file to auto download when they visit this page. How can this be done?

Hi there,

theres a few ways to do it, one of the simplest ( i think ) is to embed some Javascript on the page:

<script>setTimeout(function () { window.location = 'the_url_to_the_download_file/file.zip'; }, 5000)</script>

The 5000 sets the number of milliseconds ( eg. 5 seconds ) before the download commences.
Make sure the file is not an executable.

You could use a GP Hook Element to add the script to the wp_footer hook on your download page.

https://docs.generatepress.com/article/hooks-element-overview/

This archived topic is closed to new replies.