How to open a PDF in a new browser full window with JavaScript?

Sometimes, we want to open a PDF in a new browser full window with JavaScript.

In this article, we’ll look at how to open a PDF in a new browser full window with JavaScript.

How to open a PDF in a new browser full window with JavaScript?

To open a PDF in a new browser full window with JavaScript, we can call the window.open method with the PDF URL.

For instance, we write:

<a href="#" >open</a>

to add a link.

Then we write:

const a = document.querySelector('a')
a.onclick = () => {
  window.open('http://www.africau.edu/images/default/sample.pdf', '_blank', 'fullscreen=yes');
}

to select the anchor element with document.querySelector.

Then we set its onclick property that calls window.open to open the PDF URL in a new window.

'_blank' will make it open in a new window.

Conclusion

To open a PDF in a new browser full window with JavaScript, we can call the window.open method with the PDF URL.