Search code examples
htmlangulardownloadanchorminio

target="_blank" not working with download attribute


I am using as below:

<a [href]="pdfSrc" target="_blank" download="pdfName">Download</a>

whereas pdfSrc is coming from API response and it is a minio link.
If I use sample .pdf file target="_blank" is opening, but when I use minio link it is opening the pdf in the current tab.

I want to open minio link pdf in a new tab, I am unable to do it with minio link.


Solution

  • Try creating a method in component to open pdf in new window somthing like

    pdfSrc='http://www.africau.edu/images/default/sample.pdf';
    
     download(){
        var redirectWindow = window.open(this.pdfSrc, '_blank');
        redirectWindow.location;
     }
    

    And then call this method on href click

    <a (click)="download()" download="pdfName">Download</a>
    

    Stackbliz demo