In my Angular app, I'm attempting to have images, pdfs, and other various download links open in a new tab when clicked on in mobile. This is working as expected on a desktop, but mobile keeps opening the download in the current window, and forcing the user to use the browser back button.
<span class="link" (click)="viewFile(document.docID)">{{document.comments}}/span>
viewFile(documentName: string){
this.spinner.show();
this.formService.viewFile(documentName).subscribe((data: any) => {
this.spinner.hide();
const link = document.createElement('a');
link.href = window.URL.createObjectURL(data);
link.target = '_blank';
link.click();
}, (error) => {
this.spinner.hide();
this.toastr.error(error);
});
}
I have also tried window.open(link.href, '_blank') with no success
How can I modify my viewFile function in order to force the download to open in a new tab in mobile?
I am serving my app and the download content over https. Mixed content is not the issue.