Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *