Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a pdf file new browser window in javascript

Tags:

javascript

I need to open a pdf file in new browser tab. How to do this. I was using

var docLocation = '../downloads/doc.pdf';
window.open(docLocation,"resizeable,scrollbar"); 

But it opens a download dialog box of the browser. How to achieve this ?

like image 360
Shades88 Avatar asked Oct 11 '11 13:10

Shades88


People also ask

How do you open a PDF in JavaScript?

var docLocation = '../downloads/doc. pdf'; window. open(docLocation,"resizeable,scrollbar");

How do I get PDFs to open in browser window?

Opening a PDF document in Chrome is simple, whether you use Mac or Windows. Right click on your PDF document. Click on 'Open with'. Select Chrome or your browser of choice.


1 Answers

This code will open a pdf document in a full window from JavaScript

var pdf = MyPdf.pdf;
window.open(pdf);

A function to open windows would look like this:

function openPDF(pdf){
  window.open(pdf);
  return false;
}
like image 55
BlackMagic Avatar answered Oct 04 '22 20:10

BlackMagic