How to stop automatic download on IE 11 while using iframe

烈酒焚心 提交于 2019-12-24 05:11:29

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/26249196/how-to-stop-automatic-download-on-ie-11-while-using-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!