ARTICLE AD BOX
I have a project in React (Vite) + Typescript with Firestore database. In the project, I am storing all the PDFs in the Firestore Storage. There is one download button on one of my pages that should download the selected PDF directly without opening it in another tab.
Below is my specific existing code:
const handleDownloadClick = async (path: string) => { try { const fileRef = ref(storage, path); const url = await getDownloadURL(fileRef); const link = document.createElement("a"); link.href = url link.download = "<pdf-name>.pdf" document.body.appendChild(link); link.click(); document.body.removeChild(link); } catch (error) { console.error("Error downloading PDF: ", error); } };The above code opens the PDF in another tab to download it. But I don't want to open it in another tab; rather, I want it to download it directly.
I am not sure what I am missing here. It would be great if someone could help me with this.
