Download file and redirect to another page javascript?

Download file and redirect to another page javascript?

This is a hard one.

It’s not that easy to download and redirect the user to a new page at the same time with php, javascript. But it’s doable with jquery.

Here is the code:

1
2
3
4
5
6
7
<script>setTimeout(function () { window.location = 'http://website.com/file.zip'; }, 0)</script>
 
<script>
// Your delay in milliseconds
var delay = 3000; 
setTimeout(function(){ window.location = 'https://website.com'; }, delay);
</script>

The code will first call the auto download function.

The download pop up will appear on the screen.

After 3 seconds, the user will be redirected to the new page. The download pop up will still appear on the screen.

Add a comment: