Attempting to view pdf file though iframe using jQ

2019-07-04 11:32发布

I am trying to display a pdf file though iframe using jQuery modal popup, however, it's asking the user to download the file when the page loads instead of the pdf file being embedded inside the iframe when the modal dialog opens up.

How can I get around this?

3条回答
欢心
2楼-- · 2019-07-04 11:39

Whats causing this is different settings within the browsers because some browsers are set to display the pdf and some are set to download it.

One option is to try and create a flash object that will display the PDF.

Another option is google pdf viewer http://docs.google.com/viewer?pli=1

查看更多
神经病院院长
3楼-- · 2019-07-04 11:48

I'm using MVC to output the pdf file, and to open instead of downloading, I used this:

Response.AddHeader("Content-Disposition", "inline; filename=mypdf.pdf");

For the sake of viewing it inside a dialog I choose to use an iframe inside a div, wich became my dialog:

<div class="dialog" style="display:none; overflow:scroll;">
    <iframe src="mypdf.pdf"></iframe>
</div>
...
$(".dialog").dialog();

Make sure that your dialog div has overflow set to something different than 'auto'. Otherwise it wont display on IE.

Take a look at this link, if you need an example: http://helpdesk.toitl.com/data/p/toitl.com/dv/dialog_with_pdf/

查看更多
倾城 Initia
4楼-- · 2019-07-04 11:48

Some example code would be a big help.

I have done this using fancybox which has proved very flexible.

This link may prove useful, too. Populating Iframe with PDF - Using MVC [IE Issue]

查看更多
登录 后发表回答