简体   繁体   中英

open PDF in new window using iFrame

I want to show a PDF file preview in a browser window. When user clicks on a PDF file I want to open a new browser window and show that PDF file in it. I understand that browser can render a PDF file by itself without needing any third party libraries. So this is what I'm doing:

window.open(LinkToPDF,'_blank','width=800, height=900'); 

This does open a new window, but instead of showing a PDF it downloads it. What am I doing wrong? If I just open some PDF url in a browser it shows me the PDF then why is this code downloading that PDF instead?


EDIT: In the PDF URL content-disposition header is set as attachment which is forcing browser to download the file, is there any way to ignore this header or just download the content in javascript and display it.

Try with:

function newwin(url,w,h) {
     var win = window.open("","temp","width="+w+",height="+h+",menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=auto,resizable=yes");
     win.location.href = url;
     win.focus();
}

UPDATE:

You must specify the content with extension and/or headers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM