'Angular open a link always in a new tab Firefox

I have the following Angular code to download a PDF document. It works fine in other browsers but in Firefox when browser settings are set to "Open in Firefox" for PDF download then it doesn't open a new tab.

const blob = new Blob([data], { type: docType });
const blobDoc = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = blobDoc;
link.download = 'Filename.pdf';
link.click();

What I want is that in case of Firefox the link must always be open in a new tab. Even if when I set the target attribute, it doesn't open the new tab.

link.target = '_blank'

I tried the following and it works but then I do not get the file name.

const agent = window.navigator.userAgent.toLowerCase();
if (agent.indexOf('firefox') > -1) {
  window.open(blobDoc, '_target');
 } else {
  // Normal download
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source