-3

I want to open a pdf from an url in a new tab, so i used the usual window.open(url, '_blank'), but when i do, it open a new tab and download the PDF. How to force the navigator to display the PDF (in a new tab) instead of downloading ?

K J
  • 8,045
  • 3
  • 14
  • 36
Boursomaster
  • 202
  • 1
  • 5
  • 15

1 Answers1

0

The solution i found is to download the PDF, convert it a as a blob, then convert that blob into a new URL, then open it with window.open.

      fetch(url, {/* YOUR CUSTOM HEADER*/ })
    .then((response) => response.blob())
    .then((blob) => {
      const _url = window.URL.createObjectURL(blob);
      window.open(_url, '_blank');
    }).catch((err) => {
      console.log(err);
    });
Boursomaster
  • 202
  • 1
  • 5
  • 15