Andrew
Andrew

Reputation: 13

Click, download file and direct to another page

I'm looking for a javascript that allow me to:

1- Create a link: [a href=...

2- The link direct to a download file: domain.com/download/?id=100

3- Once a user clicked on the link (#1)

4- Download started and direct to another page

Is there anyway I can do this without any plugin, just some javascript and how?

Thank you!

Upvotes: 1

Views: 2800

Answers (2)

Nhu Trinh
Nhu Trinh

Reputation: 13986

What have you tried.

But I will also show you the way.

  1. Create a download link <a href="download file.zip" onclick="redirect">Download</a>

  2. Write a js function:

    function redirect(){ setTimeout(function(){ window.location.href="new url"; }, 3000); return true; }

Upvotes: 3

mikrowelt
mikrowelt

Reputation: 143

1- http://api.jquery.com/append/ 3 - use http://api.jquery.com/append/ again to append an iframe and using PHP set file header to type of downloading file and echo file content... 4. window.location();

Upvotes: 0

Related Questions