如何打开在&lt一个PDF文件; IFRAME&GT ;? [英] How to open a PDF file in an <iframe>?
问题描述
我想在一个iframe中打开PDF文件。我使用以下code:
I want to open the pdf file in an iframe. I am using following code:
<a class="iframeLink" href="https://something.com/HTC_One_XL_User_Guide.pdf"
jQuery1640737952376988841="85"> User guide </a>
这是在Firefox打开罚款,但它不是在IE8打开。
It is opening fine in Firefox, but it is not opening in IE8.
有谁知道如何使它也工作了IE浏览器?
Does anyone know how to make it work also for IE ?
推荐答案
使用 IFRAME
来渲染PDF文件将无法在所有的浏览器;这取决于浏览器处理PDF文件。有些浏览器(如Firefox和Chrome)有一个内置的PDF渲染这使得他们能够显示PDF内嵌其中,一些老的浏览器(可能是较旧版本的IE浏览器尝试下载,而不是文件)。
Using an iframe
to "render" a PDF will not work on all browsers; it depends on how the browser handles PDF files. Some browsers (such as Firefox and Chrome) have a built-in PDF rendered which allows them to display the PDF inline where as some older browsers (perhaps older versions of IE attempt to download the file instead).
相反,我建议您查阅 PDFObject 这是一个JavaScript库嵌入在HTML文件的PDF文件。它处理浏览器的兼容性pretty好,并将于IE8最有可能的工作。
Instead, I recommend checking out PDFObject which is a Javascript library to embed PDFs in HTML files. It handles browser compatibility pretty well and will most likely work on IE8.
在你的HTML,你可以建立一个 DIV
来显示PDF文件:
In your HTML, you could set up a div
to display the PDFs:
<div id="pdfRenderer"></div>
然后,您可以使用Javascript code嵌入到一个PDF DIV
:
var pdf = new PDFObject({
url: "https://something.com/HTC_One_XL_User_Guide.pdf",
id: "pdfRendered",
pdfOpenParams: {
view: "FitH"
}
}).embed("pdfRenderer");
这篇关于如何打开在&lt一个PDF文件; IFRAME&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!