Iframe 后备消息

Iframe Fallback Message

我在 iframe 中显示本地托管的 PDF。大多数人看到页面上嵌入了 PDF,但有一些配置会提示用户下载 PDF,从而在 PDF 所在的位置留下一大片空白。

我想在这些情况下显示某种回退消息,但未能找到有关 iframe 回退的任何信息。我宁愿避免 javascript 但如果没有其他选项可用,我会使用它。

我的 iframe 代码是 <iframe src="PDF-link-here" width="100%" height="800px" marginheight="0" frameborder="0""></iframe>

您依靠本地机器知道如何处理 PDF 文件。 如果您想确保 PDF 在该 iframe 中加载,您最好将 PDF 嵌入到页面中,而不是直接调用 PDF。

将您的 iframe src 更改为指向一个页面(小的 .htm 文件) 使用一些基本代码

<html>
<header>
<style type="text/css">
<!-- 
BODY {margin: 0} 
-->
</style>
</header>

<body>
<embed src="http://www.analysis.im/uploads/seminar/pdf-sample.pdf" width="100%" height="800px" type='application/pdf'>
</body>
</html>

您可以将嵌入更改为对象标签,这样您就可以在未加载 PDF 视图扩展的情况下包含回退,并且仍然包含嵌入。

如果您的 PDF 可公开访问,一个真正快速简便的方法是使用 Google 的在线 PDF 查看器。

<iframe src="https://docs.google.com/gview?url=http://www.yoururl.com/your.pdf&embedded=true" style="height:800px;" marginheight="0" frameborder="0"></iframe>

这样就完全不用担心本地 PDF 视图,Google 在线 PDF 查看器就是 HTML/Javascript。