jQuery 嵌入在 <object> 或 <embed> 标签中的 PDF 未在 IE 11 中加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21319484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 01:31:22  来源:igfitidea点击:

PDF Embedded in <object> or <embed> tag not loading in IE 11

jqueryhtmlpdfembedgalleriffic

提问by UID

I have to create an Image slider for which I am using:

我必须创建一个我正在使用的图像滑块:

"Galleriffic plugin > http://www.twospy.com/galleriffic/",

" Galleriffic 插件 > http://www.twospy.com/galleriffic/",

in the Image slider, along with images, I have to show PDFs for some cases.

在图像滑块以及图像中,我必须在某些情况下显示 PDF。

And to show that, I am putting the <div>which embeds PDFinside "<div class="caption">" where you can show the description related to the image.

为了表明这一点,我将<div>嵌入PDF 的内容放在“ <div class="caption">”中,您可以在其中显示与图像相关的描述。

For the Slider with PDF, you can see the full code here: http://jsfiddle.net/Z99gr/2/

对于带有 PDF 的 Slider,您可以在此处查看完整代码:http: //jsfiddle.net/Z99gr/2/

I am trying to embed the PDF using <object> or <embed>tag, It works fine in Chrome and Firefox. BUT not in IE11.

我正在尝试使用<object> or <embed>标签嵌入 PDF ,它在 Chrome 和 Firefox 中运行良好。但不是在 IE11 中。

I am not able to understand what is missing as I have create one more fiddle with just one div which embeds the PDF and its works fine in all three browser, Chrome, Firefox and IE11.

我无法理解缺少什么,因为我只用一个嵌入 PDF 的 div 创建了另一个小提琴,并且它在所有三个浏览器、Chrome、Firefox 和 IE11 中都可以正常工作。

http://jsfiddle.net/dmAM3/1/

http://jsfiddle.net/dmAM3/1/

Please look into the issue and suggest ASAP what am I missing for IE 11.

请调查这个问题并尽快建议我在 IE 11 中缺少什么。

Thanks!

谢谢!

回答by UID

I was now able to embed the PDF file IE using "<iframe>" tag.

我现在可以使用“ <iframe>”标签嵌入 PDF 文件 IE 。

I replaced "<object>" and "<embed>" tag with <iframe>and its working fine now with all 3 browsers, Firefox, Chrome and IE.

我替换了 " <object>" 和 " <embed>" 标签,<iframe>现在它在所有 3 种浏览器、Firefox、Chrome 和 IE 上都可以正常工作。

There are 2 ways of embedding PDF in IE.

有两种方法可以在 IE 中嵌入 PDF。

1st way: Call PDF directly in <iframe>

第一种方式:直接调用PDF <iframe>

Below is the updated code:

以下是更新后的代码:

<div id="pdf">
   <iframe src="https://www.adobe.com/products/pdfjobready/pdfs/pdftraag.pdf" style="width: 100%; height: 100%;" frameborder="0" scrolling="no">
        <p>It appears your web browser doesn't support iframes.</p>
   </iframe>
</div>

2nd way: if the browser doesn't have PDF reader the u can call an HTML page in <iframe>which contains <object>tag.

第二种方式:如果浏览器没有 PDF 阅读器,您可以调用<iframe>包含<object>标签的 HTML 页面

Below is the code for 2nd option

下面是第二个选项的代码

    <div id="pdf">
          <iframe src="pdf.html" style="width: 100%; height: 100%;" frameborder="0" scrolling="no">
               <p>It appears your web browser doesn't support iframes.</p>
          </iframe>
   </div>

Code for "pdf.html"

pdf.html”的代码

<body>
    <object data="lorem.pdf" type="application/pdf">
        <p>It appears you don't have Adobe Reader or PDF support in this web browser. <a href="lorem.pdf">Click here to download the PDF</a>. Or <a href="http://get.adobe.com/reader/" target="_blank">click here to install Adobe Reader</a>.</p>
       <embed src="lorem.pdf" type="application/pdf" />
    </object>
</body>

This worked for me!!!

这对我有用!!!

Here is the WORKING Fiddle : http://jsfiddle.net/stmjvz4f/

这是工作小提琴:http: //jsfiddle.net/stmjvz4f/

Hope it will be helpful for others in future!

希望以后能对其他人有所帮助!

回答by Jason Roell

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 all the way back to IE8.

我建议查看 PDFObject,它是一个用于在 HTML 文件中嵌入 PDF 的 Javascript 库。它可以很好地处理浏览器兼容性,并且很可能会一直工作到 IE8。

In your HTML, you could set up a div to display the PDFs:

在您的 HTML 中,您可以设置一个 div 来显示 PDF:

<div id="pdfRenderer"></div>

Then, you can have Javascript code to embed a PDF in that div:

然后,您可以使用 Javascript 代码在该 div 中嵌入 PDF:

var pdf = new PDFObject({
  url: "https://something.com/HTC_One_XL_User_Guide.pdf",
  id: "pdfRendered",
  pdfOpenParams: {
    view: "FitH"
  }
}).embed("pdfRenderer");

回答by Johan Velthuis

Don't put a 'type' attribute in the <object>, just in <embed> like this: The type attribute in <object> caused a permission error from Adobe Reader in IE11.

不要将“type”属性放在 <object> 中,而只是放在 <embed> 中,如下所示: <object> 中的 type 属性导致 IE11 中 Adob​​e Reader 的权限错误。

<object data="mydocument.pdf">
<p><a href="mydocument.pdf">Download</a></p>
<embed type="application/pdf" src="mydocument.pdf" />
</object>

You don't have to put this in an iframe. It can show controls, so I don't think it will work inside a slider as expected.

你不必把它放在 iframe 中。它可以显示控件,所以我认为它不会按预期在滑块内工作。