如何在使用iframe时停止在IE 11上自动下载 [英] How to stop automatic download on IE 11 while using iframe

查看:741
本文介绍了如何在使用iframe时停止在IE 11上自动下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我给了一个iframe标签的源代码,我的问题是,当页面加载到IE时,下载自动开始,它通常发生在安装在Windows 8上的IE中。

 < div> < iframe src =../../ Images / Sample.pdfwidth =800pxheight =800px>< / iframe> < / DIV> 


解决方案


没有安装Adobe Reader插件
。在这种情况下,IE(无论哪个版本)没有
知道如何渲染它,它只会下载文件(例如,Chrome,为b $ b例如,有自己的嵌入式PDF渲染器)。

那就是说。不是显示PDF的最佳方法(不要忘记
与移动浏览器的兼容性,例如Safari)。某些浏览器
将始终在外部应用程序(或
另一个浏览器窗口)内打开该文件。我发现的最好和最兼容的方式是
有点棘手,但适用于我试过的所有浏览器(即使漂亮的
过时): 保留您的但不要在其中显示PDF,它将被填充
与包含标签的HTML页面。为您的PDF创建HTML
包装页面,它应该如下所示:

 < html> 
< body>
< embed src =your_url_to_pdftype =application / pdf/>
< / object>
< / body>
< / html>

当然,您仍然需要在
浏览器中安装合适的插件。如果您需要在移动设备上支持Safari
,还可以看看这篇文章。



1st。为什么嵌套在里面?你会在
SO找到答案。而不是嵌套标签,你甚至可以为你的用户提供一个定制的
消息(或者一个内置的查看器,见下一段)。为什么选择HTML页面?因此,如果不支持PDF查看器
,则可以提供后备。内部查看器,纯HTML错误消息/选项
等等...



检查PDF支持非常棘手,因此您可以提供一个备用
浏览器为您的客户,看看PDF.JS项目,它非常好
,但渲染质量 - 对于桌面浏览器 - 不如
原生PDF渲染器(我没有看到任何不同的移动浏览器
,因为屏幕大小,我想)。


另见:


I have given a source in a Iframe tag, my is issue is that when the page loads on IE the download begins automatically and it generally happens on IE installed on windows 8.

<div> <iframe  src="../../Images/Sample.pdf" width="800px" height="800px" ></iframe> </div>

解决方案

It's downloaded probably because there is not Adobe Reader plug-in installed. In this case IE (it doesn't matter which version) doesn't know how to render it and it'll simply download file (Chrome, for example, has its own embedded PDF renderer).

That said. is not best way to display a PDF (do not forget compatibility with mobile browsers, for example Safari). Some browsers will always open that file inside an external application (or in another browser window). Best and most compatible way I found is a little bit tricky but works on all browsers I tried (even pretty outdated):

Keep your but do not display a PDF inside it, it'll be filled with an HTML page that consists of an tag. Create an HTML wrapping page for your PDF, it should look like this:

<html>
<body>
    <object data="your_url_to_pdf" type="application/pdf">
        <embed src="your_url_to_pdf" type="application/pdf" />
    </object>
</body>
</html>

Of course you still need the appropriate plug-in installed in the browser. Also take a look to this post if you need to support Safari on mobile devices.

1st. Why nesting inside ? You'll find answer here on SO. Instead of nested tag you may even provide a custom message for your users (or a built-in viewer, see next paragraph).

2nd. Why an HTML page? So you can provide a fallback if PDF viewer isn't supported. Internal viewer, plain HTML error messages/options and so on...

It's tricky to check PDF support so you may provide an alternate viewer for your customers, take a look to PDF.JS project, it's pretty good but rendering quality - for desktop browsers - isn't as good as a native PDF renderer (I didn't see any difference in mobile browsers because of screen size, I suppose).

See also: HTML embedded PDF iframe

这篇关于如何在使用iframe时停止在IE 11上自动下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆