I am trying to download file by clicking on download button it should open the new tab and start downloading and once the download starts it closes the tab itself basically I do not want to have any effect on the original page. Here is my current code
const downloadHandler = (file) => {
const a = document.createElement("a");
a.href = file;
a.setAttribute(`download`, file);
a.click();
};
I recommend using the download attribute for download instead of jQuery:
<a href="your_link" download> file_name </a>
This will download your file, without opening it.
<a href="https://yourlink.com" target="_blank" download>fileName</a>
This will open the HTML file in a new tab