设置iframe的自动高度 [英] Set auto height for iframe

查看:501
本文介绍了设置iframe的自动高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带pdf文件的iframe:

I've got a iframe with pdf file:

<iframe src="pdf/sample.pdf"></iframe>

如何设置iframe与pdf文件的高度相同,而没有滚动条?

How to set that the iframe is the same height as the pdf file, without scrollbars?

推荐答案

如果要显示不带滚动条的PDF,可以通过在URL中传递参数来实现. Adobe已在此处记录了这一点: http://www.adobe.com/内容/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

If you want to display the PDF without scrollbars, you can do this by passing parameters in the URL. Adobe has documented this here: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

尝试一下:

<iframe src="pdf/sample.pdf#view=fit"></iframe>

您并没有完全设置iframe的高度以适合PDF,但这可能是最可靠的解决方案,因为它与浏览器无关,不需要JavaScript.

You are not exactly setting the height of the iframe to fit the PDF, but it is probably the most robust solution since it is browser-independent and doesn't require JavaScript.

这是丹尼尔发表评论后的更新.

Here is an update after Daniel's comment.

我创建了一个测试HTML,如下所示:

I created a test HTML as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Untitled Page</title>
</head>
<body>
   <iframe src="http://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf#view=fit&toolbar=0&navpanes=0"
      width="300px" height="400px"></iframe>
</body>
</html>

这是在Chrome中的外观:

This is how it looks in Chrome:

这是预期的.

请注意,我还关闭了工具栏和导航窗格,以便为页面留出空间.

Note that I also turned off the toolbar and the navpane so there is room for the page.

这篇关于设置iframe的自动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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