Reputation: 14521
I am trying to set up my website to download a file when a user clicks a specific link and then also take them to a separate page. From what I have gathered, this is not possible using pure HTML since we can't chain A tags together. Is this understanding correct? If so, how would I approach doing this in Javascript?
For context, I am trying to mimic the behavior on this site: https://code.visualstudio.com/download when you click the download VS Code button.
Upvotes: 1
Views: 559
Reputation: 29
I can think of two ways to do this.
You can handle all that in an event listener function for the download button to open a new location and also open a file link (to trigger download).
You can handle it that an event listener opens a new link then triggers download with window.onload or window.contentLoaded.
Upvotes: 1