Answer the question
In order to leave comments, you need to log in
How to execute a certain function and after its execution trigger a click on a link?
I have the functionality of downloading a pdf file through the react-pdf library. It is
necessary that everything that is in the test function work first and only then it downloads the pdf file from the link.
How can this be implemented?
<Button href={instance.url} download="test.pdf" color='primary' block outline className='mb-75' disabled={pdfCheck} onClick = {() => test()}>
Скачать
</Button>
Answer the question
In order to leave comments, you need to log in
For example, you can move the download to a function:
const element = document.createElement('a');
element.href = instance.url;
element.setAttribute('download', 'test.pdf');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question