iframe达到页面底部 [英] iframe reaches bottom of page

查看:129
本文介绍了iframe达到页面底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让< iframe> 的高度恰好达到页面的底部?很难通过使用 height:xx%来判断,它可能依赖于浏览器。

Is there a way to make the height of the <iframe> reach exactly the bottom of the page? It is hard to judge by using height:xx%, and it might be dependent on browser.

代码如下:

The code is below:

<!DOCTYPE html>
<html>
<body style="margin:0">
<p style="margin:10px"> hello </p>
<iframe src="http://www.weather.com" style="width:100%; height:95%"></iframe>
</body>
</html>


推荐答案

使用JavaScript / jQuery,您可以精确设置正确对于 IFRAME 元素来说,不需要访问框架本身的DOM(跨域问题),依赖于表格或绝对定位(如果上面的内容框架在高度上是动态的):

Using JavaScript/jQuery, you can precisely set the right dimension for the IFRAME element, without the need to access to DOM of the frame itself (cross-domain issues), relying on tables or absolute positioning (useless if the content above the frame is dynamic in height):

$(function() {
    var aboveHeight = $("#aboveFrame").outerHeight(true);
    $(window).resize(function() {
        $('#frame').height( $(window).height() - aboveHeight );
    }).resize();
});

示例: http://jsfiddle.net/hongaar/jsdYz/

这篇关于iframe达到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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