0

I have the following code to fetch a PDF file and open it in a new tab:

$(document).on('click', '#downloadInvoice', function () {
    showLoader();
    $.ajax({
        type: 'POST',
        url: _baseUrl + 'orders/downloadinvoice/' + $(this).data('id'),
        xhrFields: {
            responseType: 'blob'
        },
        success: (response) => {
            const blob = new Blob([response], { type: 'application/pdf' }),
                  url  = window.URL.createObjectURL(blob)

            window.open(url);
        },
        error: () => {
            toastr.error('Error!');
        },
        complete: () => {
            hideLoader();
        }
    });
});

It works as intended in Chrome but in Firefox, it downloads the file automatically and I have to look for it in Downloads and open it manually.

Is it that Firefox prevents the opening of a new tab or do I need to add something in my code? Strangely, I have not found anything online relating to this issue.

Jolan
  • 681
  • 12
  • 39
  • 1
    Does this answer your question? [Open a URL in a new tab (and not a new window)](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window) – Hyyan Abo Fakher Jul 22 '22 at 13:49
  • @HyyanAboFakher your suggestion is not related to my question – Jolan Jul 22 '22 at 14:00

0 Answers0