0

This is my function to download zip file autoDownload.current.click() - automatically click on HTML element which download my zip file. But Problem is page used to reload while this process. How i can prevent my page to reload.

const downloadZipFile = () => { 
    console.log('download');
    autoDownload.current.click();
}

I need something like this.

const downloadZipFile = () => { 
    console.log('download');
    autoDownload.current.click((e) => {
      e.preventDefalut();
    });
}
1
  • You can try wrapping the component being clicked with a forwardRef and providing the click handler. Here's an example: stackoverflow.com/a/66883184/13023138 Commented Dec 9, 2022 at 16:13

1 Answer 1

0

Have you tried adding an 'onClick' property to the link/button with a function that includes the e.preventDefault() ? Not sure exactly how you're setting this up, but below has some ideas (using reactjs).

const downloadZipFile = (e) => {
    e.preventDefault()
    // Add your download zip functionality here
}

// Example of function that will execute on page load
React.useEffect(() => {
    downloadZipFile()
}, [])

return (
    <Button id='someid' onClick={downloadZipFile} />
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.