将iFrame高度调整为内容高度

时间:2014-09-12 04:17:40

标签: javascript html node.js

我正在iFrame中加载网站跨域。我想调整iFrame的大小以匹配我正在加载的网站的高度。 Sniply就是这样做的,我想模仿这个功能。任何人都知道他们在这里表演的是什么样的巫术?

http://snip.ly/Z9nv#https://forums.eveonline.com/default.aspx?g=posts&m=5009807

看起来他们不仅从跨域网站访问文档,而且使用不同的协议(HTTP / HTTPS)。任何见解?看起来他们可能会将iFrame的高度设置为一些不可思议的高值,并且当它滚动到底部时以某种方式停止滚动。救命!

编辑:一些额外的细节.. 我在后端使用一些插件对我正在尝试提交的URL进行一些分析: https://github.com/mikeal/requesthttps://github.com/tmpvar/jsdom。我是否可以使用这两个插件中的一个来让我获得文档的高度?

EDIT2:我不想在iframe中滚动 - 我希望它与它所包含的文档的高度相匹配。

2 个答案:

答案 0 :(得分:0)

我认为你必须设置CSS。如果有更多的iframe,你可以使用一个类。

iframe {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
border: 0;
height: 100%;
min-width: 100%;
width: 10px;
-webkit-overflow-scrolling: touch;
overflow: scroll;
}

您必须将自己的元素设置为position:fixed

答案 1 :(得分:0)

将CSS设置为此似乎可以正常工作

iframe {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border: 0;
  height: 100%;
  min-width: 100%;
  width: 10px;
}

这是一个实时样本



iframe {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border: 0;
  height: 100%;
  min-width: 100%;
  width: 10px;
}

<div>test</div>
<iframe src="https://slashdot.org"></iframe>
&#13;
&#13;
&#13;

相关问题