Currently, I am retrieving a base64 encoded PDF from an API REST service.
After some trial and error, I came up with this method for decoding and downloading the PDF:
const linkSource = 'data:application/pdf;base64,' + apiResponse;
const downloadLink = document.createElement('a');
const fileName = 'xx.pdf';
downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
While the code works as intended, I actually need the PDF to be opened in a new tab instead of being downloaded.
I attempted the following approach, but it doesn't appear to be successful:
window.open(linkSource, '_blank');
Is there a way I can modify the downloadLink
element so that it opens in a new tab instead of triggering a download? Essentially, I am looking for the behavior similar to using
<a target="_blank">
.