I'm trying to programmatically click an <a> element which has the download attribute and an href to download a file from a server. However if there is an error downloading, the server will return an html page with an error status code. Because of the HTML5 download attribute it tries to force download this html page or downloads a server error file. Is there a way I can have this open the html error file in a new tab instead of downloading? I am already setting the target attribute to _blank.
You can request the file using XMLHttpRequest or fetch, if no error occurs, set <a> element href, download attributes, else redirect user to document displaying error response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With